root
commited on
Commit
·
bccb493
1
Parent(s):
51a671a
update
Browse files
app.py
CHANGED
|
@@ -370,19 +370,28 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 370 |
example_url_vl = gr.State(value=None)
|
| 371 |
|
| 372 |
if targeted_recognition_examples:
|
| 373 |
-
targeted_paths = [e[0] for e in targeted_recognition_examples]
|
| 374 |
targeted_state = gr.State(targeted_paths)
|
| 375 |
-
gr.Markdown("**Element-level Recognition Examples (Click an image to load)**")
|
| 376 |
-
gallery_targeted = gr.Gallery(value=targeted_paths, columns=4, height=400, preview=False, label=None, allow_preview=False)
|
| 377 |
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
return url, update_preview_visibility(url)
|
| 381 |
|
| 382 |
gallery_targeted.select(
|
| 383 |
fn=on_gallery_select_for_vl,
|
| 384 |
inputs=[targeted_state],
|
| 385 |
-
outputs=[example_url_vl, preview_vl_html]
|
| 386 |
)
|
| 387 |
|
| 388 |
with gr.Column(scale=7):
|
|
|
|
| 370 |
example_url_vl = gr.State(value=None)
|
| 371 |
|
| 372 |
if targeted_recognition_examples:
|
| 373 |
+
targeted_paths = [e[0] for e in targeted_recognition_examples] # List[str]
|
| 374 |
targeted_state = gr.State(targeted_paths)
|
|
|
|
|
|
|
| 375 |
|
| 376 |
+
gallery_targeted = gr.Gallery(
|
| 377 |
+
value=targeted_paths, columns=4, height=400,
|
| 378 |
+
preview=False, label=None, allow_preview=False
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
def on_gallery_select_for_vl(paths, evt: gr.SelectData):
|
| 382 |
+
idx = evt.index
|
| 383 |
+
if isinstance(idx, (list, tuple)):
|
| 384 |
+
idx = idx[0]
|
| 385 |
+
try:
|
| 386 |
+
url = paths[int(idx)]
|
| 387 |
+
except Exception:
|
| 388 |
+
raise gr.Error(f"Invalid index from gallery: {evt.index}")
|
| 389 |
return url, update_preview_visibility(url)
|
| 390 |
|
| 391 |
gallery_targeted.select(
|
| 392 |
fn=on_gallery_select_for_vl,
|
| 393 |
inputs=[targeted_state],
|
| 394 |
+
outputs=[example_url_vl, preview_vl_html],
|
| 395 |
)
|
| 396 |
|
| 397 |
with gr.Column(scale=7):
|