Update app.py
Browse files
app.py
CHANGED
|
@@ -215,19 +215,27 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
| 215 |
)
|
| 216 |
submit_btn = gr.Button(value="Submit", variant="primary")
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
gr.Examples(
|
| 219 |
-
examples=
|
| 220 |
-
["./examples/app_store.png", "Download Kindle."],
|
| 221 |
-
["./examples/ios_setting.png", "Turn off Do not disturb."],
|
| 222 |
-
["./examples/apple_music.png", "Star to favorite."],
|
| 223 |
-
["./examples/map.png", "Boston."],
|
| 224 |
-
["./examples/wallet.png", "Scan a QR code."],
|
| 225 |
-
["./examples/word.png", "More shapes."],
|
| 226 |
-
["./examples/web_shopping.png", "Proceed to checkout."],
|
| 227 |
-
["./examples/web_forum.png", "Post my comment."],
|
| 228 |
-
["./examples/safari_google.png", "Click on search bar."],
|
| 229 |
-
],
|
| 230 |
inputs=[imagebox, textbox],
|
|
|
|
|
|
|
| 231 |
examples_per_page=3
|
| 232 |
)
|
| 233 |
|
|
@@ -245,13 +253,11 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
| 245 |
downvote_btn = gr.Button(value="Too bad!", variant="secondary")
|
| 246 |
clear_btn = gr.Button(value="🗑️ Clear", interactive=True)
|
| 247 |
|
| 248 |
-
def on_submit(image, query):
|
| 249 |
if image is None:
|
| 250 |
raise ValueError("No image provided. Please upload an image before submitting.")
|
| 251 |
|
| 252 |
session_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 253 |
-
print("image_path:", image)
|
| 254 |
-
is_example_image = isinstance(image, str) and image.startswith("./examples/")
|
| 255 |
|
| 256 |
result_image, click_coords, image_path = run_showui(image, query, session_id)
|
| 257 |
|
|
@@ -261,7 +267,7 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
| 261 |
|
| 262 |
submit_btn.click(
|
| 263 |
on_submit,
|
| 264 |
-
[imagebox, textbox],
|
| 265 |
[output_img, output_coords, state_image_path, state_session_id, state_is_example_image],
|
| 266 |
)
|
| 267 |
|
|
@@ -295,4 +301,4 @@ if __name__ == "__main__":
|
|
| 295 |
server_port=7860,
|
| 296 |
ssr_mode=False,
|
| 297 |
debug=True,
|
| 298 |
-
)
|
|
|
|
| 215 |
)
|
| 216 |
submit_btn = gr.Button(value="Submit", variant="primary")
|
| 217 |
|
| 218 |
+
examples = [
|
| 219 |
+
["./examples/app_store.png", "Download Kindle."],
|
| 220 |
+
["./examples/ios_setting.png", "Turn off Do not disturb."],
|
| 221 |
+
["./examples/apple_music.png", "Star to favorite."],
|
| 222 |
+
["./examples/map.png", "Boston."],
|
| 223 |
+
["./examples/wallet.png", "Scan a QR code."],
|
| 224 |
+
["./examples/word.png", "More shapes."],
|
| 225 |
+
["./examples/web_shopping.png", "Proceed to checkout."],
|
| 226 |
+
["./examples/web_forum.png", "Post my comment."],
|
| 227 |
+
["./examples/safari_google.png", "Click on search bar."],
|
| 228 |
+
]
|
| 229 |
+
|
| 230 |
+
def set_example_flag(image_path, query):
|
| 231 |
+
is_example = any(image_path == example[0] for example in examples)
|
| 232 |
+
return image_path, query, is_example
|
| 233 |
+
|
| 234 |
gr.Examples(
|
| 235 |
+
examples=examples,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
inputs=[imagebox, textbox],
|
| 237 |
+
outputs=[state_is_example_image],
|
| 238 |
+
fn=set_example_flag,
|
| 239 |
examples_per_page=3
|
| 240 |
)
|
| 241 |
|
|
|
|
| 253 |
downvote_btn = gr.Button(value="Too bad!", variant="secondary")
|
| 254 |
clear_btn = gr.Button(value="🗑️ Clear", interactive=True)
|
| 255 |
|
| 256 |
+
def on_submit(image, query, is_example_image):
|
| 257 |
if image is None:
|
| 258 |
raise ValueError("No image provided. Please upload an image before submitting.")
|
| 259 |
|
| 260 |
session_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
|
|
|
| 261 |
|
| 262 |
result_image, click_coords, image_path = run_showui(image, query, session_id)
|
| 263 |
|
|
|
|
| 267 |
|
| 268 |
submit_btn.click(
|
| 269 |
on_submit,
|
| 270 |
+
[imagebox, textbox, state_is_example_image],
|
| 271 |
[output_img, output_coords, state_image_path, state_session_id, state_is_example_image],
|
| 272 |
)
|
| 273 |
|
|
|
|
| 301 |
server_port=7860,
|
| 302 |
ssr_mode=False,
|
| 303 |
debug=True,
|
| 304 |
+
)
|