Spaces:
Running
Running
Dongxu Li
commited on
Commit
·
f6fc05a
1
Parent(s):
1365f85
adjust layout.
Browse files
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 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 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 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 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)
|