lsyzz commited on
Commit
8b7935c
·
1 Parent(s): 6fee716

add examples

Browse files
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 (New Independent Tab) =====================
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
- # 复用 Targeted examples (用户可以从中选取适合 Spotting 的图片)
391
- if targeted_recognition_examples:
392
- targeted_paths_spot = [e[0] for e in targeted_recognition_examples]
393
- spot_state = gr.State(targeted_paths_spot)
394
- gallery_spot = gr.Gallery(value=targeted_paths_spot, columns=4, height=400, preview=False, label=None, allow_preview=False)
 
 
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=7860)
 
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

  • SHA256: a22d026f8a85e7c810f6bf6890616a62e3bde94f22f4f85773cfd03c3075d690
  • Pointer size: 131 Bytes
  • Size of remote file: 545 kB
examples/complex/vl1.510.png ADDED

Git LFS Details

  • SHA256: e4b7121ccb40859af1595f05d9e5cba1412cc4f8e1dbccdb089be45ed0cddfe8
  • Pointer size: 132 Bytes
  • Size of remote file: 3.2 MB
examples/complex/vl1.52.png ADDED

Git LFS Details

  • SHA256: e1470e5972c5ec69757fef11a2a951f99c44a099db3752189a6cc3d8d0a70534
  • Pointer size: 131 Bytes
  • Size of remote file: 402 kB
examples/complex/vl1.53.png ADDED

Git LFS Details

  • SHA256: 1be1f3dfeb363cdaf8d895c90874ab5e9a763099c31f4f0cc8db4fde0ede6dcc
  • Pointer size: 131 Bytes
  • Size of remote file: 535 kB
examples/complex/vl1.54.png ADDED

Git LFS Details

  • SHA256: 522c04704415a7a5c2eb0f050ce186bd74a6fdb8d1ffa6d651e5f595d4c837e4
  • Pointer size: 131 Bytes
  • Size of remote file: 477 kB
examples/complex/vl1.55.png ADDED

Git LFS Details

  • SHA256: 4fb8c141c56e4b4a2fa03bf5d0c6067f2ed560b25e40a31474a439e97c27be4f
  • Pointer size: 131 Bytes
  • Size of remote file: 518 kB
examples/complex/vl1.56.png ADDED

Git LFS Details

  • SHA256: a5ef1fdd7adbd89cee353e62fa83b5600d76c7f4dd6bcc49642fc44bc20d3a3a
  • Pointer size: 131 Bytes
  • Size of remote file: 481 kB
examples/complex/vl1.57.png ADDED

Git LFS Details

  • SHA256: 01d36d6699b89b9f9ff88dc0f2a0369950e5526b022d65753bee6af64c462b60
  • Pointer size: 132 Bytes
  • Size of remote file: 1.12 MB
examples/complex/vl1.58.png ADDED

Git LFS Details

  • SHA256: 4ad52df318c30c34f4cf4c66483ad14d6841b66db106a6c8d0f730babf6cfdf5
  • Pointer size: 131 Bytes
  • Size of remote file: 687 kB
examples/complex/vl1.59.png ADDED

Git LFS Details

  • SHA256: 8712f39fae3463b7faad620d396207041195f51312b9b9b03c8acb0480bf3661
  • Pointer size: 131 Bytes
  • Size of remote file: 700 kB
examples/spotting/vl1_5_1.png ADDED

Git LFS Details

  • SHA256: df971f45840b24533d01d2fc5805daa885e93334dc21083c5a02f9a6137ec7c6
  • Pointer size: 130 Bytes
  • Size of remote file: 79.6 kB
examples/spotting/vl1_5_2.png ADDED

Git LFS Details

  • SHA256: d754623eb687fd369d6f756ad799f60e06de402dd418639e8663327ba12d9b7e
  • Pointer size: 131 Bytes
  • Size of remote file: 708 kB
examples/spotting/vl1_5_3.png ADDED

Git LFS Details

  • SHA256: f1f50d8175066d7c62e0d7cf35cc82fa4bd6fffe7fb4cf9c68e805750b96e5d4
  • Pointer size: 131 Bytes
  • Size of remote file: 364 kB
examples/spotting/vl1_5_4.png ADDED

Git LFS Details

  • SHA256: 5af19a2233ef9c4b68e38b5ab8d2d377fe15d0417a543b9c7c3f3301bc0679a4
  • Pointer size: 131 Bytes
  • Size of remote file: 858 kB
examples/spotting/vl1_5_5.png ADDED

Git LFS Details

  • SHA256: 922fbf9da0a9d8b8930b5fec46ce7c4a1a253b1a52a874ed1c150eeadcb8d420
  • Pointer size: 131 Bytes
  • Size of remote file: 277 kB
examples/spotting/vl1_5_6.png ADDED

Git LFS Details

  • SHA256: fef94c235dc7e9769e9fd4e2a8aab0ce6705ba1964952ab6c1155fcc5848708e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.2 MB
examples/spotting/vl1_5_7.png ADDED

Git LFS Details

  • SHA256: 2be4afdc0821c1c009c60f04eda64a8208aff054ec423e214825b3374b40bb65
  • Pointer size: 131 Bytes
  • Size of remote file: 108 kB
examples/targeted/vl1_5_1.png ADDED

Git LFS Details

  • SHA256: 3d311b5b4321fb5bf058e0df471925bebe5378be7379675c3e6a8121094f7995
  • Pointer size: 130 Bytes
  • Size of remote file: 54 kB
examples/targeted/vl1_5_10.png ADDED

Git LFS Details

  • SHA256: 90407a02a186b2c39ae3f4b66051127f84ea0c8fbf4d0e5ae42cece05461e42e
  • Pointer size: 131 Bytes
  • Size of remote file: 419 kB
examples/targeted/vl1_5_11.png ADDED

Git LFS Details

  • SHA256: 023a7d8dba5c030fac7461d0e4443103254f61122a07a9fbb1eeec0bbc7b2ed1
  • Pointer size: 130 Bytes
  • Size of remote file: 68.6 kB
examples/targeted/vl1_5_12.png ADDED

Git LFS Details

  • SHA256: 1beacfdf3d796d6795493bd0d5205852376e339e7735254fdf3d9a3c93685929
  • Pointer size: 131 Bytes
  • Size of remote file: 153 kB
examples/targeted/vl1_5_2.png ADDED

Git LFS Details

  • SHA256: 81f7625acc39d3a7aa0d43d32b6dc50fe320f1abd6255692e614641429cff4b9
  • Pointer size: 131 Bytes
  • Size of remote file: 669 kB
examples/targeted/vl1_5_3.png ADDED

Git LFS Details

  • SHA256: b455d3db93b7f6ff4a11494560ca47a3d93444dde2fce8c9557f00f4a0fc2022
  • Pointer size: 132 Bytes
  • Size of remote file: 1.74 MB
examples/targeted/vl1_5_4.png ADDED

Git LFS Details

  • SHA256: 160fa682cfa76d60b2943bd32b298f7473ae4fe74eac894d46a9b9ff69c64131
  • Pointer size: 132 Bytes
  • Size of remote file: 2.68 MB
examples/targeted/vl1_5_5.png ADDED

Git LFS Details

  • SHA256: 4acd20bf68f7827767cb9632e53c6f97a4df60756a705b4d58e65b2862baa73b
  • Pointer size: 131 Bytes
  • Size of remote file: 218 kB
examples/targeted/vl1_5_6.png ADDED

Git LFS Details

  • SHA256: 98a1d15d500de0ff6ab5073f73fa6d29238d834657d58d80c68bd557aeb31d9f
  • Pointer size: 131 Bytes
  • Size of remote file: 247 kB
examples/targeted/vl1_5_7.png ADDED

Git LFS Details

  • SHA256: c6c586fa48afd46e72f7745042ca97cf3df795905a8f394fc4a6bef2be91f2c2
  • Pointer size: 131 Bytes
  • Size of remote file: 270 kB
examples/targeted/vl1_5_8.png ADDED

Git LFS Details

  • SHA256: 9c5732abfd358b31f602d6b2acf064f23cea2ad428b126ece4ed485a95e2c90c
  • Pointer size: 131 Bytes
  • Size of remote file: 144 kB
examples/targeted/vl1_5_9.png ADDED

Git LFS Details

  • SHA256: 82368310fe1d44ec0a626a735c5dbf41e425fdc16f6429eded6dfbd8047ca9aa
  • Pointer size: 131 Bytes
  • Size of remote file: 427 kB