Manmay Nakhashi commited on
Commit
459924b
·
1 Parent(s): 05bb874

Pin SDK to 4.44.1 + monkey-patch gradio_client schema bool TypeError

Browse files

The HF ZeroGPU image hardcodes gradio[oauth]==4.44.1, so we can't bump
gradio. The bug ('const' in <bool> in get_type) is patched at import
time by replacing gradio_client.utils.get_type and _json_schema_to_python_type
with bool-tolerant wrappers.

Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +26 -2
  3. requirements.txt +0 -2
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🎭
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 5.7.1
8
  app_file: app.py
9
  pinned: true
10
  license: other
 
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: true
10
  license: other
app.py CHANGED
@@ -11,8 +11,32 @@ import sys
11
  import tempfile
12
  import time
13
 
14
- import gradio as gr
15
- import spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Local src import.
18
  sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"))
 
11
  import tempfile
12
  import time
13
 
14
+ # Workaround gradio_client 1.3.0 bug: get_type/json_schema_to_python_type crash when
15
+ # a JSON schema field (e.g. additionalProperties) is a bool literal instead of a dict.
16
+ # Patching has to happen BEFORE `import gradio` triggers the schema walk on launch.
17
+ import gradio_client.utils as _gcu # noqa: E402
18
+
19
+ _orig_get_type = _gcu.get_type
20
+ _orig_json_to_py = _gcu._json_schema_to_python_type
21
+
22
+
23
+ def _safe_get_type(schema):
24
+ if not isinstance(schema, dict):
25
+ return "Any"
26
+ return _orig_get_type(schema)
27
+
28
+
29
+ def _safe_json_to_py(schema, defs=None):
30
+ if not isinstance(schema, dict):
31
+ return "Any"
32
+ return _orig_json_to_py(schema, defs)
33
+
34
+
35
+ _gcu.get_type = _safe_get_type
36
+ _gcu._json_schema_to_python_type = _safe_json_to_py
37
+
38
+ import gradio as gr # noqa: E402
39
+ import spaces # noqa: E402
40
 
41
  # Local src import.
42
  sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"))
requirements.txt CHANGED
@@ -11,8 +11,6 @@ sentencepiece>=0.1.99
11
  transformers>=4.45.0
12
  huggingface_hub>=0.20.0,<1.0
13
  bitsandbytes>=0.43.0
14
- gradio>=5.0.0
15
- gradio-client>=1.5.0
16
  spaces>=0.30.0
17
  soundfile>=0.12.0
18
  resemble-perth @ git+https://github.com/resemble-ai/Perth.git@master
 
11
  transformers>=4.45.0
12
  huggingface_hub>=0.20.0,<1.0
13
  bitsandbytes>=0.43.0
 
 
14
  spaces>=0.30.0
15
  soundfile>=0.12.0
16
  resemble-perth @ git+https://github.com/resemble-ai/Perth.git@master