Spaces:
Sleeping
Sleeping
lsyzz commited on
Commit ·
8b7935c
1
Parent(s): 6fee716
add examples
Browse files- app.py +15 -11
- examples/complex/vl1.51.png +3 -0
- examples/complex/vl1.510.png +3 -0
- examples/complex/vl1.52.png +3 -0
- examples/complex/vl1.53.png +3 -0
- examples/complex/vl1.54.png +3 -0
- examples/complex/vl1.55.png +3 -0
- examples/complex/vl1.56.png +3 -0
- examples/complex/vl1.57.png +3 -0
- examples/complex/vl1.58.png +3 -0
- examples/complex/vl1.59.png +3 -0
- examples/spotting/vl1_5_1.png +3 -0
- examples/spotting/vl1_5_2.png +3 -0
- examples/spotting/vl1_5_3.png +3 -0
- examples/spotting/vl1_5_4.png +3 -0
- examples/spotting/vl1_5_5.png +3 -0
- examples/spotting/vl1_5_6.png +3 -0
- examples/spotting/vl1_5_7.png +3 -0
- examples/targeted/vl1_5_1.png +3 -0
- examples/targeted/vl1_5_10.png +3 -0
- examples/targeted/vl1_5_11.png +3 -0
- examples/targeted/vl1_5_12.png +3 -0
- examples/targeted/vl1_5_2.png +3 -0
- examples/targeted/vl1_5_3.png +3 -0
- examples/targeted/vl1_5_4.png +3 -0
- examples/targeted/vl1_5_5.png +3 -0
- examples/targeted/vl1_5_6.png +3 -0
- examples/targeted/vl1_5_7.png +3 -0
- examples/targeted/vl1_5_8.png +3 -0
- examples/targeted/vl1_5_9.png +3 -0
app.py
CHANGED
|
@@ -77,10 +77,16 @@ def _get_examples_from_dir(dir_path: str) -> List[List[str]]:
|
|
| 77 |
examples.append([img_url])
|
| 78 |
return examples
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
TARGETED_EXAMPLES_DIR = "examples/targeted"
|
| 81 |
COMPLEX_EXAMPLES_DIR = "examples/complex"
|
|
|
|
|
|
|
| 82 |
targeted_recognition_examples = _get_examples_from_dir(TARGETED_EXAMPLES_DIR)
|
| 83 |
complex_document_examples = _get_examples_from_dir(COMPLEX_EXAMPLES_DIR)
|
|
|
|
| 84 |
|
| 85 |
# =========================
|
| 86 |
# UI Helpers
|
|
@@ -341,7 +347,6 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 341 |
with gr.Row(elem_classes=["prompt-grid"]):
|
| 342 |
btn_table = gr.Button("Table Recognition", variant="secondary")
|
| 343 |
btn_chart = gr.Button("Chart Recognition", variant="secondary")
|
| 344 |
-
# Spotting 按钮已移除,Seal 按钮保留
|
| 345 |
with gr.Row(elem_classes=["prompt-grid"]):
|
| 346 |
btn_seal = gr.Button("Seal Recognition", variant="secondary")
|
| 347 |
|
|
@@ -376,7 +381,7 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 376 |
(btn_seal, "Seal Recognition")]:
|
| 377 |
btn.click(run_vl, [file_vl, example_url_vl, gr.State(prompt)], [md_preview_vl, md_raw_vl, gr.HTML(visible=False)])
|
| 378 |
|
| 379 |
-
# ===================== Tab 3: Spotting (
|
| 380 |
with gr.Tab("Spotting"):
|
| 381 |
with gr.Row():
|
| 382 |
with gr.Column(scale=5):
|
|
@@ -387,11 +392,13 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 387 |
btn_run_spot = gr.Button("Run Spotting", variant="primary")
|
| 388 |
|
| 389 |
example_url_spot = gr.State(value=None)
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
|
|
|
|
|
|
| 395 |
|
| 396 |
def on_gallery_spot(paths, evt: gr.SelectData):
|
| 397 |
url = paths[int(evt.index)] if isinstance(evt.index, int) else paths[evt.index[0]]
|
|
@@ -411,9 +418,6 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 411 |
def run_spotting_wrapper(fp, ex):
|
| 412 |
src = fp if fp else ex
|
| 413 |
if not src: raise gr.Error("Please upload an image.")
|
| 414 |
-
# 调用通用函数,prompt 固定为 "Spotting"
|
| 415 |
-
# 返回值顺序: (md_preview, md_raw(json字符串), vis_html)
|
| 416 |
-
# Spotting tab 不需要 md_preview,所以这里用 dummy 接收
|
| 417 |
_, json_res, vis_res = handle_targeted_recognition(src, "Spotting")
|
| 418 |
return vis_res, json_res
|
| 419 |
|
|
@@ -424,4 +428,4 @@ with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as
|
|
| 424 |
)
|
| 425 |
|
| 426 |
if __name__ == "__main__":
|
| 427 |
-
demo.queue(max_size=64).launch(server_name="0.0.0.0", server_port=
|
|
|
|
| 77 |
examples.append([img_url])
|
| 78 |
return examples
|
| 79 |
|
| 80 |
+
# =========================
|
| 81 |
+
# Load Examples
|
| 82 |
+
# =========================
|
| 83 |
TARGETED_EXAMPLES_DIR = "examples/targeted"
|
| 84 |
COMPLEX_EXAMPLES_DIR = "examples/complex"
|
| 85 |
+
SPOTTING_EXAMPLES_DIR = "examples/spotting" # [新增] Spotting 目录
|
| 86 |
+
|
| 87 |
targeted_recognition_examples = _get_examples_from_dir(TARGETED_EXAMPLES_DIR)
|
| 88 |
complex_document_examples = _get_examples_from_dir(COMPLEX_EXAMPLES_DIR)
|
| 89 |
+
spotting_recognition_examples = _get_examples_from_dir(SPOTTING_EXAMPLES_DIR) # [新增] 加载 Spotting 示例
|
| 90 |
|
| 91 |
# =========================
|
| 92 |
# UI Helpers
|
|
|
|
| 347 |
with gr.Row(elem_classes=["prompt-grid"]):
|
| 348 |
btn_table = gr.Button("Table Recognition", variant="secondary")
|
| 349 |
btn_chart = gr.Button("Chart Recognition", variant="secondary")
|
|
|
|
| 350 |
with gr.Row(elem_classes=["prompt-grid"]):
|
| 351 |
btn_seal = gr.Button("Seal Recognition", variant="secondary")
|
| 352 |
|
|
|
|
| 381 |
(btn_seal, "Seal Recognition")]:
|
| 382 |
btn.click(run_vl, [file_vl, example_url_vl, gr.State(prompt)], [md_preview_vl, md_raw_vl, gr.HTML(visible=False)])
|
| 383 |
|
| 384 |
+
# ===================== Tab 3: Spotting (Independent Tab) =====================
|
| 385 |
with gr.Tab("Spotting"):
|
| 386 |
with gr.Row():
|
| 387 |
with gr.Column(scale=5):
|
|
|
|
| 392 |
btn_run_spot = gr.Button("Run Spotting", variant="primary")
|
| 393 |
|
| 394 |
example_url_spot = gr.State(value=None)
|
| 395 |
+
|
| 396 |
+
# [修改] 使用 spotting_recognition_examples
|
| 397 |
+
if spotting_recognition_examples:
|
| 398 |
+
spotting_paths = [e[0] for e in spotting_recognition_examples]
|
| 399 |
+
spot_state = gr.State(spotting_paths)
|
| 400 |
+
|
| 401 |
+
gallery_spot = gr.Gallery(value=spotting_paths, columns=4, height=400, preview=False, label=None, allow_preview=False)
|
| 402 |
|
| 403 |
def on_gallery_spot(paths, evt: gr.SelectData):
|
| 404 |
url = paths[int(evt.index)] if isinstance(evt.index, int) else paths[evt.index[0]]
|
|
|
|
| 418 |
def run_spotting_wrapper(fp, ex):
|
| 419 |
src = fp if fp else ex
|
| 420 |
if not src: raise gr.Error("Please upload an image.")
|
|
|
|
|
|
|
|
|
|
| 421 |
_, json_res, vis_res = handle_targeted_recognition(src, "Spotting")
|
| 422 |
return vis_res, json_res
|
| 423 |
|
|
|
|
| 428 |
)
|
| 429 |
|
| 430 |
if __name__ == "__main__":
|
| 431 |
+
demo.queue(max_size=64).launch(server_name="0.0.0.0", server_port=8080)
|
examples/complex/vl1.51.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.510.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.52.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.53.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.54.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.55.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.56.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.57.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.58.png
ADDED
|
Git LFS Details
|
examples/complex/vl1.59.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_1.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_2.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_3.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_4.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_5.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_6.png
ADDED
|
Git LFS Details
|
examples/spotting/vl1_5_7.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_1.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_10.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_11.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_12.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_2.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_3.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_4.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_5.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_6.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_7.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_8.png
ADDED
|
Git LFS Details
|
examples/targeted/vl1_5_9.png
ADDED
|
Git LFS Details
|