chansung commited on
Commit
9baa3f7
·
1 Parent(s): 1c28431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -4
app.py CHANGED
@@ -63,6 +63,37 @@ STYLE = """
63
  margin-left: 20px;
64
  margin-right: 70px;
65
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  """
67
 
68
  get_local_storage = """
@@ -125,12 +156,16 @@ def set_chatbot(btn, ld):
125
  GradioAlpacaChatPPManager.from_json(json.dumps(ppm_str))
126
  for ppm_str in ld
127
  ]
128
- return res[choice].build_uis(), choice
 
 
 
 
129
 
130
  with gr.Blocks(css=STYLE, elem_id='container-col') as block:
131
  idx = gr.State(0)
132
  local_data = gr.JSON({},visible=False)
133
-
134
  with gr.Row():
135
  with gr.Column(scale=1, min_width=180):
136
  gr.Markdown("GradioChat", elem_id="left-top")
@@ -144,6 +179,14 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
144
  fifth = gr.Button("5th", elem_classes=["custom-btn"])
145
 
146
  with gr.Column(scale=8, elem_id="right-pane"):
 
 
 
 
 
 
 
 
147
  chatbot = gr.Chatbot(elem_id='chatbot')
148
  instruction_txtbox = gr.Textbox(
149
  placeholder="Ask anything", label="",
@@ -155,9 +198,17 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
155
  btn.click(
156
  set_chatbot,
157
  [btn, local_data],
158
- [chatbot, idx]
159
  )
160
 
 
 
 
 
 
 
 
 
161
  instruction_txtbox.submit(
162
  add_pingpong,
163
  [idx, local_data, instruction_txtbox],
@@ -174,4 +225,4 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
174
  _js=get_local_storage,
175
  )
176
 
177
- block.queue().launch(debug=True)
 
63
  margin-left: 20px;
64
  margin-right: 70px;
65
  }
66
+
67
+ #test-elem {
68
+ z-index: 100;
69
+ position: absolute;
70
+ width: 50%;
71
+ top: 50%;
72
+ height: 50%;
73
+ left: 50%;
74
+ transform: translate(-50%, -50%);
75
+ border-radius: 35px;
76
+ padding: 15px;
77
+ text-align: center;
78
+ }
79
+
80
+ .example-btn {
81
+ padding-top: 20px !important;
82
+ padding-bottom: 20px !important;
83
+ padding-left: 5px !important;
84
+ padding-right: 5px !important;
85
+ background: linear-gradient(to bottom right, #f7faff, #ffffff) !important;
86
+ box-shadow: none !important;
87
+ border-radius: 20px !important;
88
+ }
89
+
90
+ .example-btn:hover {
91
+ box-shadow: 0.5px 0.5px 0.5px gray !important
92
+ }
93
+
94
+ #example-title {
95
+ margin-bottom: 15px;
96
+ }
97
  """
98
 
99
  get_local_storage = """
 
156
  GradioAlpacaChatPPManager.from_json(json.dumps(ppm_str))
157
  for ppm_str in ld
158
  ]
159
+ empty = len(res[choice].pingpongs) == 0
160
+ return res[choice].build_uis(), choice, gr.update(visible=empty)
161
+
162
+ def set_example(btn):
163
+ return btn, gr.update(visible=False)
164
 
165
  with gr.Blocks(css=STYLE, elem_id='container-col') as block:
166
  idx = gr.State(0)
167
  local_data = gr.JSON({},visible=False)
168
+
169
  with gr.Row():
170
  with gr.Column(scale=1, min_width=180):
171
  gr.Markdown("GradioChat", elem_id="left-top")
 
179
  fifth = gr.Button("5th", elem_classes=["custom-btn"])
180
 
181
  with gr.Column(scale=8, elem_id="right-pane"):
182
+ with gr.Column(elem_id="test-elem", visible=False) as example_block:
183
+ gr.Markdown("## Begin with examples", elem_id="example-title")
184
+
185
+ with gr.Row():
186
+ ex_btn1 = gr.Button("hello world", elem_classes=["example-btn"])
187
+ ex_btn2 = gr.Button("what's up?", elem_classes=["example-btn"])
188
+ ex_btn3 = gr.Button("this is a GradioChat", elem_classes=["example-btn"])
189
+
190
  chatbot = gr.Chatbot(elem_id='chatbot')
191
  instruction_txtbox = gr.Textbox(
192
  placeholder="Ask anything", label="",
 
198
  btn.click(
199
  set_chatbot,
200
  [btn, local_data],
201
+ [chatbot, idx, example_block]
202
  )
203
 
204
+ ex_btns = [ex_btn1, ex_btn2, ex_btn3]
205
+ for btn in ex_btns:
206
+ btn.click(
207
+ set_example,
208
+ [btn],
209
+ [instruction_txtbox, example_block]
210
+ )
211
+
212
  instruction_txtbox.submit(
213
  add_pingpong,
214
  [idx, local_data, instruction_txtbox],
 
225
  _js=get_local_storage,
226
  )
227
 
228
+ block.launch(debug=True)