asemxin2000 commited on
Commit
feb4510
·
verified ·
1 Parent(s): 1ef9632

Fix broken dropdown serialization in cpu-basic wrapper

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -7,35 +7,37 @@ from mineru.cli.gradio_app import main as mineru_gradio
7
 
8
  OUTPUT_ROOT = Path("/tmp/mineru-space-output")
9
  CPU_SAFE_BACKENDS = ["pipeline"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
  def patch_gradio_defaults() -> None:
13
- original_dropdown_init = gr.Dropdown.__init__
14
  original_launch = gr.Blocks.launch
15
 
16
- def patched_dropdown_init(self, *args, **kwargs):
17
- choices = kwargs.get("choices")
18
- value = kwargs.get("value")
19
-
20
- if (
21
- isinstance(choices, list)
22
- and {"pipeline", "vlm-auto-engine", "hybrid-auto-engine"}.issubset(
23
- set(choices)
24
- )
25
- and value == "hybrid-auto-engine"
26
- ):
27
- kwargs["choices"] = CPU_SAFE_BACKENDS
28
- kwargs["value"] = "pipeline"
29
-
30
- return original_dropdown_init(self, *args, **kwargs)
31
-
32
  def patched_launch(self, *args, **kwargs):
33
  # HF Spaces can mis-detect localhost accessibility under Gradio 5 SSR.
 
34
  kwargs.setdefault("ssr_mode", False)
35
  kwargs.setdefault("show_error", True)
36
  return original_launch(self, *args, **kwargs)
37
 
38
- gr.Dropdown.__init__ = patched_dropdown_init
39
  gr.Blocks.launch = patched_launch
40
 
41
 
 
7
 
8
  OUTPUT_ROOT = Path("/tmp/mineru-space-output")
9
  CPU_SAFE_BACKENDS = ["pipeline"]
10
+ GPU_BACKENDS = {"pipeline", "vlm-auto-engine", "hybrid-auto-engine"}
11
+
12
+
13
+ def enforce_cpu_space_defaults(demo: gr.Blocks) -> None:
14
+ for block in demo.blocks.values():
15
+ if isinstance(block, gr.Dropdown):
16
+ raw_choices = list(getattr(block, "choices", []) or [])
17
+ normalized = {
18
+ choice[1] if isinstance(choice, (tuple, list)) and len(choice) >= 2 else choice
19
+ for choice in raw_choices
20
+ }
21
+ if GPU_BACKENDS.issubset(normalized):
22
+ block.choices = [(name, name) for name in CPU_SAFE_BACKENDS]
23
+ block.value = "pipeline"
24
+ block.info = (
25
+ "Traditional Multi-model pipeline parsing, supports multiple "
26
+ "languages, hallucination-free."
27
+ )
28
+ continue
29
 
30
 
31
  def patch_gradio_defaults() -> None:
 
32
  original_launch = gr.Blocks.launch
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def patched_launch(self, *args, **kwargs):
35
  # HF Spaces can mis-detect localhost accessibility under Gradio 5 SSR.
36
+ enforce_cpu_space_defaults(self)
37
  kwargs.setdefault("ssr_mode", False)
38
  kwargs.setdefault("show_error", True)
39
  return original_launch(self, *args, **kwargs)
40
 
 
41
  gr.Blocks.launch = patched_launch
42
 
43