ibcplateformes Claude Opus 4.6 commited on
Commit
14442a3
·
1 Parent(s): c88afa4

Monkey-patch gradio_client bug for additionalProperties bool

Browse files

HF Spaces pins gradio 4.44.0 which has a bug in gradio_client where
additionalProperties=True (bool) causes TypeError in get_type().
This patch intercepts the call and handles bool schemas gracefully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -11,6 +11,30 @@ import shutil
11
 
12
  import gradio as gr
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Setup logging
15
  logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
16
  logger = logging.getLogger(__name__)
 
11
 
12
  import gradio as gr
13
 
14
+ # ── Monkey-patch gradio_client bug with additionalProperties ──────────────
15
+ # Fix TypeError: argument of type 'bool' is not iterable in get_type()
16
+ # This bug exists in gradio 4.44.0's gradio_client when additionalProperties
17
+ # is a bool (True) instead of a dict schema.
18
+ try:
19
+ import gradio_client.utils as _gc_utils
20
+
21
+ _original_json_schema_to_python_type = _gc_utils._json_schema_to_python_type
22
+
23
+ def _patched_json_schema_to_python_type(schema, defs=None):
24
+ # Fix: if additionalProperties is a bool, handle it gracefully
25
+ if isinstance(schema, bool):
26
+ return "Any"
27
+ if isinstance(schema, dict) and "additionalProperties" in schema:
28
+ ap = schema["additionalProperties"]
29
+ if isinstance(ap, bool):
30
+ schema = dict(schema) # don't mutate original
31
+ schema["additionalProperties"] = {"type": "object"} if ap else {}
32
+ return _original_json_schema_to_python_type(schema, defs)
33
+
34
+ _gc_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
35
+ except Exception:
36
+ pass # If patch fails, continue anyway
37
+
38
  # Setup logging
39
  logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
40
  logger = logging.getLogger(__name__)