AI4deeperScience commited on
Commit
a4b9349
Β·
verified Β·
1 Parent(s): 7bef156

fix: monkey-patch gradio_client bool-schema bug, remove ssr_mode

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -23,6 +23,21 @@ import seaborn as sns
23
  import gradio as gr
24
  from PIL import Image
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # ---------- path setup ----------
27
  ROOT = Path(__file__).parent
28
  sys.path.insert(0, str(ROOT))
@@ -768,4 +783,4 @@ with gr.Blocks(
768
 
769
  if __name__ == "__main__":
770
  demo.launch(server_name="0.0.0.0", server_port=7860,
771
- show_api=False, ssr_mode=False)
 
23
  import gradio as gr
24
  from PIL import Image
25
 
26
+ # ── Patch gradio_client bool-schema bug (affects gradio 5.0–5.20) ──────────
27
+ # gradio_client._json_schema_to_python_type calls "const" in schema where
28
+ # schema can be a JSON-Schema boolean (e.g. additionalProperties: false).
29
+ # Python raises TypeError; this shim returns "any" for non-dict schemas.
30
+ import gradio_client.utils as _gc_utils
31
+ _orig_schema_fn = _gc_utils._json_schema_to_python_type
32
+
33
+ def _safe_schema_fn(schema, defs=None):
34
+ if not isinstance(schema, dict):
35
+ return "any"
36
+ return _orig_schema_fn(schema, defs)
37
+
38
+ _gc_utils._json_schema_to_python_type = _safe_schema_fn
39
+ # ────────────────────────────────────────────────────────────────────────────
40
+
41
  # ---------- path setup ----------
42
  ROOT = Path(__file__).parent
43
  sys.path.insert(0, str(ROOT))
 
783
 
784
  if __name__ == "__main__":
785
  demo.launch(server_name="0.0.0.0", server_port=7860,
786
+ show_api=False)