Dongxu Li commited on
Commit
f6fc05a
1 Parent(s): 1365f85

adjust layout.

Browse files
Files changed (1) hide show
  1. app.py +84 -89
app.py CHANGED
@@ -136,10 +136,6 @@ examples = [
136
  ["house.png", "How could someone get out of the house?"],
137
  ["flower.jpg", "Question: What is this flower and where is it's origin? Answer:"],
138
  ["forbidden_city.webp", "In what dynasties was this place build?"],
139
- # [
140
- # "sunset.png",
141
- # "Write a romantic message that goes along this photo.",
142
- # ],
143
  ]
144
 
145
  with gr.Blocks() as iface:
@@ -152,97 +148,96 @@ with gr.Blocks() as iface:
152
  with gr.Column():
153
  image_input = gr.Image(type="pil")
154
 
155
- with gr.Row():
156
- sampling = gr.Radio(
157
- choices=["Beam search", "Nucleus sampling"],
158
- value="Beam search",
159
- label="Text Decoding Method",
160
- interactive=True,
161
- )
162
-
163
- temperature = gr.Slider(
164
- minimum=0.5,
165
- maximum=1.0,
166
- value=0.8,
167
- step=0.1,
168
- interactive=True,
169
- label="Temperature (used with nucleus sampling)",
170
- )
171
-
172
- len_penalty = gr.Slider(
173
- minimum=-1.0,
174
- maximum=2.0,
175
- value=1.0,
176
- step=0.2,
177
- interactive=True,
178
- label="Length Penalty (set to larger for longer sequence, used with beam search)",
179
- )
180
-
181
- rep_penalty = gr.Slider(
182
- minimum=1.0,
183
- maximum=5.0,
184
- value=1.5,
185
- step=0.5,
186
- interactive=True,
187
- label="Repeat Penalty (larger value prevents repetition)",
188
- )
189
-
190
- with gr.Row():
191
- caption_output = gr.Textbox(lines=2, label="Caption Output (from OPT)")
192
- caption_button = gr.Button(
193
- value="Caption it!", interactive=True, variant="primary"
194
- )
195
- caption_button.click(
196
- inference_caption,
197
- [
198
- image_input,
199
- sampling,
200
- temperature,
201
- len_penalty,
202
- rep_penalty,
203
- ],
204
- [caption_output],
205
- )
206
 
207
  with gr.Column():
208
- chat_input = gr.Textbox(lines=2, label="Chat Input")
209
-
210
- with gr.Row():
211
- chatbot = gr.Chatbot(label="Chat Output (from FlanT5)")
212
- image_input.change(lambda: (None, "", "", []), [], [chatbot, chat_input, caption_output, state])
213
-
214
- with gr.Row():
215
-
216
- clear_button = gr.Button(value="Clear", interactive=True)
217
- clear_button.click(
218
- lambda: ("", None, [], []),
219
- [],
220
- [chat_input, image_input, chatbot, state],
221
- )
222
-
223
- submit_button = gr.Button(
224
- value="Submit", interactive=True, variant="primary"
225
- )
226
- submit_button.click(
227
- inference_chat,
228
- [
229
- image_input,
230
- chat_input,
231
- sampling,
232
- temperature,
233
- len_penalty,
234
- rep_penalty,
235
- state,
236
- ],
237
- [chatbot, state],
238
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  examples = gr.Examples(
241
  examples=examples,
242
  inputs=[image_input, chat_input],
243
- # outputs=[chatbot, state],
244
- # run_on_click=True,
245
- # fn = inference_chat,
246
  )
247
 
248
  iface.queue(concurrency_count=1, api_open=False, max_size=10)
 
136
  ["house.png", "How could someone get out of the house?"],
137
  ["flower.jpg", "Question: What is this flower and where is it's origin? Answer:"],
138
  ["forbidden_city.webp", "In what dynasties was this place build?"],
 
 
 
 
139
  ]
140
 
141
  with gr.Blocks() as iface:
 
148
  with gr.Column():
149
  image_input = gr.Image(type="pil")
150
 
151
+ # with gr.Row():
152
+ sampling = gr.Radio(
153
+ choices=["Beam search", "Nucleus sampling"],
154
+ value="Beam search",
155
+ label="Text Decoding Method",
156
+ interactive=True,
157
+ )
158
+
159
+ temperature = gr.Slider(
160
+ minimum=0.5,
161
+ maximum=1.0,
162
+ value=1.0,
163
+ step=0.1,
164
+ interactive=True,
165
+ label="Temperature (used with nucleus sampling)",
166
+ )
167
+
168
+ len_penalty = gr.Slider(
169
+ minimum=-1.0,
170
+ maximum=2.0,
171
+ value=1.0,
172
+ step=0.2,
173
+ interactive=True,
174
+ label="Length Penalty (set to larger for longer sequence, used with beam search)",
175
+ )
176
+
177
+ rep_penalty = gr.Slider(
178
+ minimum=1.0,
179
+ maximum=5.0,
180
+ value=1.5,
181
+ step=0.5,
182
+ interactive=True,
183
+ label="Repeat Penalty (larger value prevents repetition)",
184
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
  with gr.Column():
187
+
188
+ with gr.Column():
189
+ # with gr.Row():
190
+ caption_output = gr.Textbox(lines=1, label="Caption Output (from OPT)")
191
+ caption_button = gr.Button(
192
+ value="Caption it!", interactive=True, variant="primary"
193
+ )
194
+ caption_button.click(
195
+ inference_caption,
196
+ [
197
+ image_input,
198
+ sampling,
199
+ temperature,
200
+ len_penalty,
201
+ rep_penalty,
202
+ ],
203
+ [caption_output],
204
+ )
205
+
206
+ with gr.Column():
207
+ chat_input = gr.Textbox(lines=1, label="Chat Input")
208
+ with gr.Row():
209
+ chatbot = gr.Chatbot(label="Chat Output (from FlanT5)")
210
+ image_input.change(lambda: (None, "", "", []), [], [chatbot, chat_input, caption_output, state])
211
+
212
+ with gr.Row():
213
+
214
+ clear_button = gr.Button(value="Clear", interactive=True)
215
+ clear_button.click(
216
+ lambda: ("", None, [], []),
217
+ [],
218
+ [chat_input, image_input, chatbot, state],
219
+ )
220
+
221
+ submit_button = gr.Button(
222
+ value="Submit", interactive=True, variant="primary"
223
+ )
224
+ submit_button.click(
225
+ inference_chat,
226
+ [
227
+ image_input,
228
+ chat_input,
229
+ sampling,
230
+ temperature,
231
+ len_penalty,
232
+ rep_penalty,
233
+ state,
234
+ ],
235
+ [chatbot, state],
236
+ )
237
 
238
  examples = gr.Examples(
239
  examples=examples,
240
  inputs=[image_input, chat_input],
 
 
 
241
  )
242
 
243
  iface.queue(concurrency_count=1, api_open=False, max_size=10)