cstr commited on
Commit
ddfe9f6
·
1 Parent(s): d1b858f

fix: upgrade to Gradio 5.29.0 to resolve Starlette/Jinja2 compat breaks

Browse files

Gradio 4.44.1 is broken with current HF Space deps:
- TemplateResponse(name, context) vs new (request, name, context) → TypeError: unhashable type: 'dict'
- gradio_client additionalProperties bool crash (also fixed natively in gradio-client 1.x)

Gradio 5.29.0 ships gradio-client 1.x which has both fixes built-in.
Monkey-patches are kept but made conditional (hasattr) so they are no-ops on 5.x.

Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +18 -18
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🎙️
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: false
10
  python_version: 3.10.13
 
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
10
  python_version: 3.10.13
app.py CHANGED
@@ -1,25 +1,25 @@
1
  import gradio as gr
2
 
3
- # gradio_client crashes when JSON Schema contains `additionalProperties: true`
4
- # (a boolean, not a dict). Two code paths hit this:
5
- # 1. get_type() does `if "const" in schema` TypeError on bool
6
- # 2. _json_schema_to_python_type() → APIInfoParseError("Cannot parse schema True")
7
- # Patch both to treat non-dict schemas as "Any"/"unknown".
8
  import gradio_client.utils as _gcu
9
 
10
- _orig_get_type = _gcu.get_type
11
- def _safe_get_type(schema):
12
- if not isinstance(schema, dict):
13
- return "unknown"
14
- return _orig_get_type(schema)
15
- _gcu.get_type = _safe_get_type
16
-
17
- _orig_j2p = _gcu._json_schema_to_python_type
18
- def _safe_j2p(schema, defs=None):
19
- if not isinstance(schema, dict):
20
- return "Any"
21
- return _orig_j2p(schema, defs)
22
- _gcu._json_schema_to_python_type = _safe_j2p
 
 
23
 
24
  import os
25
  import time
 
1
  import gradio as gr
2
 
3
+ # gradio_client <1.x crashes when JSON Schema has `additionalProperties: true`
4
+ # (a boolean). Fixed in gradio-client 1.x (Gradio 5+), but patch defensively
5
+ # for older installs. Both code paths that hit the bug are guarded.
 
 
6
  import gradio_client.utils as _gcu
7
 
8
+ if hasattr(_gcu, "get_type"):
9
+ _orig_get_type = _gcu.get_type
10
+ def _safe_get_type(schema):
11
+ if not isinstance(schema, dict):
12
+ return "unknown"
13
+ return _orig_get_type(schema)
14
+ _gcu.get_type = _safe_get_type
15
+
16
+ if hasattr(_gcu, "_json_schema_to_python_type"):
17
+ _orig_j2p = _gcu._json_schema_to_python_type
18
+ def _safe_j2p(schema, defs=None):
19
+ if not isinstance(schema, dict):
20
+ return "Any"
21
+ return _orig_j2p(schema, defs)
22
+ _gcu._json_schema_to_python_type = _safe_j2p
23
 
24
  import os
25
  import time