mamungtai-sat pormungtai commited on
Commit
5788c76
·
1 Parent(s): 6fe92dc

Monkeypatch gradio_client to fix api_info bool-schema crash (#4)

Browse files

- Monkeypatch gradio_client to fix api_info bool-schema crash (80d9741e3023f3c0985bda916a3126941be268b0)


Co-authored-by: pormungtailaw <pormungtai@users.noreply.huggingface.co>

Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +20 -0
__pycache__/app.cpython-310.pyc ADDED
Binary file (6.4 kB). View file
 
app.py CHANGED
@@ -15,6 +15,26 @@ import traceback
15
  import spaces # must be imported before torch on ZeroGPU
16
  import gradio as gr
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  import pipeline_manager as pm
19
 
20
  MAX_SEED = 2**31 - 1
 
15
  import spaces # must be imported before torch on ZeroGPU
16
  import gradio as gr
17
 
18
+ # --- Workaround for a gradio_client bug: "argument of type 'bool' is not iterable".
19
+ # Some component api_info schemas carry a boolean `additionalProperties`, which the
20
+ # schema-to-type walker chokes on, crashing get_api_info() and the whole launch.
21
+ # Short-circuit any non-dict schema to "Any". Version-independent and harmless. ---
22
+ import gradio_client.utils as _gcu
23
+
24
+ _orig_get_type = _gcu.get_type
25
+ def _safe_get_type(schema):
26
+ if not isinstance(schema, dict):
27
+ return "Any"
28
+ return _orig_get_type(schema)
29
+ _gcu.get_type = _safe_get_type
30
+
31
+ _orig_j2pt = _gcu._json_schema_to_python_type
32
+ def _safe_j2pt(schema, defs=None):
33
+ if isinstance(schema, bool):
34
+ return "Any"
35
+ return _orig_j2pt(schema, defs)
36
+ _gcu._json_schema_to_python_type = _safe_j2pt
37
+
38
  import pipeline_manager as pm
39
 
40
  MAX_SEED = 2**31 - 1