jieluo1024 commited on
Commit
4345562
·
1 Parent(s): 00b2f48

chore: update Gradio to 6.12.0 and fix HF Spaces compatibility

Browse files

- Update Gradio from 5.12.0 to 6.12.0
- Fix Gradio 6.x API changes (theme/css parameters moved to launch)
- Remove deprecated show_api parameter
- Fix circular import in root app.py using importlib
- Update HF Spaces SDK version in README
- Remove audioop-lts (not needed for Python 3.11)

Files changed (5) hide show
  1. README.md +1 -1
  2. app.py +29 -4
  3. demo/README.md +1 -1
  4. demo/app.py +5 -5
  5. requirements.txt +1 -4
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 📄
4
  colorFrom: green
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
4
  colorFrom: green
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 6.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -7,19 +7,44 @@ root stays uncluttered.
7
 
8
  from __future__ import annotations
9
 
 
10
  import sys
11
  from pathlib import Path
12
 
13
- _DEMO_DIR = Path(__file__).resolve().parent / "demo"
14
- sys.path.insert(0, str(_DEMO_DIR))
15
 
16
- from app import demo # noqa: E402,F401 re-exported for HF Spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  if __name__ == "__main__":
19
  import os
20
 
 
 
 
 
 
 
 
21
  demo.queue(max_size=8).launch(
22
  server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
23
  server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
24
- show_api=False,
 
25
  )
 
7
 
8
  from __future__ import annotations
9
 
10
+ import importlib.util
11
  import sys
12
  from pathlib import Path
13
 
14
+ _REPO_ROOT = Path(__file__).resolve().parent
 
15
 
16
+ # Add packages to path (needed before importing demo modules)
17
+ for pkg in ("pdfsys-core", "pdfsys-router", "pdfsys-parser-mupdf", "pdfsys-bench"):
18
+ src = _REPO_ROOT / "packages" / pkg / "src"
19
+ if src.is_dir() and str(src) not in sys.path:
20
+ sys.path.insert(0, str(src))
21
+
22
+ # Add demo dir to path (needed for pipeline import)
23
+ _DEMO_DIR = _REPO_ROOT / "demo"
24
+ if str(_DEMO_DIR) not in sys.path:
25
+ sys.path.insert(0, str(_DEMO_DIR))
26
+
27
+ # Load demo app from demo/app.py using importlib to avoid name collision
28
+ _demo_module_path = _DEMO_DIR / "app.py"
29
+ spec = importlib.util.spec_from_file_location("demo_app", _demo_module_path)
30
+ _demo_module = importlib.util.module_from_spec(spec)
31
+ sys.modules["demo_app"] = _demo_module
32
+ spec.loader.exec_module(_demo_module)
33
+ demo = _demo_module.demo # noqa: F401 — re-exported for HF Spaces
34
 
35
  if __name__ == "__main__":
36
  import os
37
 
38
+ import gradio as gr
39
+
40
+ CSS = """
41
+ .small-num input { font-weight: 600; font-size: 1.1rem; }
42
+ footer { display: none !important; }
43
+ """
44
+
45
  demo.queue(max_size=8).launch(
46
  server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
47
  server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
48
+ theme=gr.themes.Soft(primary_hue="emerald"),
49
+ css=CSS,
50
  )
demo/README.md CHANGED
@@ -51,7 +51,7 @@ The root `README.md` already contains the required [Spaces YAML config](https://
51
  ---
52
  title: PDFSystem MNBVC Demo
53
  sdk: gradio
54
- sdk_version: 4.44.0
55
  app_file: app.py
56
  license: apache-2.0
57
  ---
 
51
  ---
52
  title: PDFSystem MNBVC Demo
53
  sdk: gradio
54
+ sdk_version: 6.12.0
55
  app_file: app.py
56
  license: apache-2.0
57
  ---
demo/app.py CHANGED
@@ -128,7 +128,7 @@ def process_pdf(
128
  "_No markdown yet._",
129
  empty_segments,
130
  empty_features,
131
- {},
132
  )
133
 
134
  pdf_path = Path(pdf_file)
@@ -154,7 +154,7 @@ def process_pdf(
154
  f"```\n{tb}\n```",
155
  empty_segments,
156
  empty_features,
157
- err_json,
158
  )
159
 
160
  # ------------------------------------------------------------- summary
@@ -225,6 +225,7 @@ def process_pdf(
225
  raw = result.to_record()
226
  raw["router_features_full"] = result.router_features
227
  raw["segments_full"] = result.segments
 
228
 
229
  return (
230
  summary_md,
@@ -237,7 +238,7 @@ def process_pdf(
237
  md_text,
238
  seg_rows,
239
  feat_rows,
240
- raw,
241
  )
242
 
243
 
@@ -279,7 +280,6 @@ def build_demo() -> gr.Blocks:
279
  with gr.Column(scale=2, min_width=520):
280
  summary_md = gr.Markdown(
281
  "Upload a PDF and click **Run Pipeline**.",
282
- label="Summary",
283
  )
284
 
285
  with gr.Row():
@@ -327,7 +327,7 @@ def build_demo() -> gr.Blocks:
327
  label="Curated subset (full 124-dim vector in Raw JSON)",
328
  )
329
  with gr.Tab("Raw JSON"):
330
- raw_json = gr.JSON(label="All pipeline outputs")
331
 
332
  # ----------------------------------------------------------- wiring
333
  outputs = [
 
128
  "_No markdown yet._",
129
  empty_segments,
130
  empty_features,
131
+ "{}",
132
  )
133
 
134
  pdf_path = Path(pdf_file)
 
154
  f"```\n{tb}\n```",
155
  empty_segments,
156
  empty_features,
157
+ json.dumps(err_json, indent=2, ensure_ascii=False),
158
  )
159
 
160
  # ------------------------------------------------------------- summary
 
225
  raw = result.to_record()
226
  raw["router_features_full"] = result.router_features
227
  raw["segments_full"] = result.segments
228
+ raw_json_str = json.dumps(raw, indent=2, ensure_ascii=False, default=str)
229
 
230
  return (
231
  summary_md,
 
238
  md_text,
239
  seg_rows,
240
  feat_rows,
241
+ raw_json_str,
242
  )
243
 
244
 
 
280
  with gr.Column(scale=2, min_width=520):
281
  summary_md = gr.Markdown(
282
  "Upload a PDF and click **Run Pipeline**.",
 
283
  )
284
 
285
  with gr.Row():
 
327
  label="Curated subset (full 124-dim vector in Raw JSON)",
328
  )
329
  with gr.Tab("Raw JSON"):
330
+ raw_json = gr.Code(label="All pipeline outputs", language="json")
331
 
332
  # ----------------------------------------------------------- wiring
333
  outputs = [
requirements.txt CHANGED
@@ -2,15 +2,12 @@
2
  # Note: Local workspace packages (pdfsys-*) are loaded via sys.path in demo/app.py
3
  # and do not need editable installation in HF Spaces.
4
 
5
- # --- Python 3.13 compatibility (audioop removed) --------------------------
6
- audioop-lts
7
-
8
  # --- CPU-only torch (HF Spaces free tier is CPU) --------------------------
9
  --extra-index-url https://download.pytorch.org/whl/cpu
10
  torch>=2.1,<3.0
11
 
12
  # --- Third-party runtime deps -------------------------------------------
13
- gradio==5.12.0
14
  huggingface-hub>=0.26,<0.29
15
  pymupdf>=1.24
16
  xgboost>=2.0
 
2
  # Note: Local workspace packages (pdfsys-*) are loaded via sys.path in demo/app.py
3
  # and do not need editable installation in HF Spaces.
4
 
 
 
 
5
  # --- CPU-only torch (HF Spaces free tier is CPU) --------------------------
6
  --extra-index-url https://download.pytorch.org/whl/cpu
7
  torch>=2.1,<3.0
8
 
9
  # --- Third-party runtime deps -------------------------------------------
10
+ gradio>=5.12.0,<7.0
11
  huggingface-hub>=0.26,<0.29
12
  pymupdf>=1.24
13
  xgboost>=2.0