ricklon commited on
Commit
75469a7
·
1 Parent(s): 29ae2cb

Make Gradio launch arguments version-compatible for 5.x/6.x

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  import sys
7
  import tempfile
8
  import shutil
 
9
  from PIL import Image, ImageDraw, ImageFont, ImageOps
10
  import fitz
11
  import re
@@ -1368,7 +1369,14 @@ def update_page_selector(file_path):
1368
  label=f"Select Page (1-{page_count})")
1369
  return gr.update(visible=False)
1370
 
1371
- with gr.Blocks(title="DeepSeek-OCR-2") as demo:
 
 
 
 
 
 
 
1372
  gr.Markdown("""
1373
  # 🧮 DeepSeek-OCR-2 — Math Rendering Edition
1374
  **Convert documents to markdown, extract text, parse figures, and locate specific content with bounding boxes.**
@@ -1669,9 +1677,13 @@ if __name__ == "__main__":
1669
  # server_name="0.0.0.0" is needed locally (WSL2 → Windows access)
1670
  # On HuggingFace Spaces, SPACE_ID is set and Gradio handles binding automatically
1671
  local = not os.environ.get("SPACE_ID")
1672
- demo.queue(max_size=20).launch(
1673
- theme=gr.themes.Soft(),
1674
- server_name="0.0.0.0" if local else None,
1675
- head=PREVIEW_CSS,
1676
- ssr_mode=False, # SSR is experimental in Gradio 6 and breaks HF Spaces routing
1677
- )
 
 
 
 
 
6
  import sys
7
  import tempfile
8
  import shutil
9
+ import inspect
10
  from PIL import Image, ImageDraw, ImageFont, ImageOps
11
  import fitz
12
  import re
 
1369
  label=f"Select Page (1-{page_count})")
1370
  return gr.update(visible=False)
1371
 
1372
+ blocks_kwargs = {"title": "DeepSeek-OCR-2"}
1373
+ if hasattr(gr, "themes") and hasattr(gr.themes, "Soft"):
1374
+ try:
1375
+ blocks_kwargs["theme"] = gr.themes.Soft()
1376
+ except Exception:
1377
+ pass
1378
+
1379
+ with gr.Blocks(**blocks_kwargs) as demo:
1380
  gr.Markdown("""
1381
  # 🧮 DeepSeek-OCR-2 — Math Rendering Edition
1382
  **Convert documents to markdown, extract text, parse figures, and locate specific content with bounding boxes.**
 
1677
  # server_name="0.0.0.0" is needed locally (WSL2 → Windows access)
1678
  # On HuggingFace Spaces, SPACE_ID is set and Gradio handles binding automatically
1679
  local = not os.environ.get("SPACE_ID")
1680
+ queued = demo.queue(max_size=20)
1681
+ launch_sig = inspect.signature(queued.launch)
1682
+ launch_kwargs = {}
1683
+ if "server_name" in launch_sig.parameters:
1684
+ launch_kwargs["server_name"] = "0.0.0.0" if local else None
1685
+ if "head" in launch_sig.parameters:
1686
+ launch_kwargs["head"] = PREVIEW_CSS
1687
+ if "ssr_mode" in launch_sig.parameters:
1688
+ launch_kwargs["ssr_mode"] = False # SSR breaks HF Spaces routing in Gradio 6
1689
+ queued.launch(**launch_kwargs)