Pybunny commited on
Commit
01d1f93
·
verified ·
1 Parent(s): c83cbc2

Re-apply schema-walker monkey-patch

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -6,7 +6,35 @@ recall-constrained cutoffs are pulled from the HF model repo
6
  the Space so the demo works offline of the laptop.
7
  """
8
 
9
- from __future__ import annotations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  import json
12
  from pathlib import Path
 
6
  the Space so the demo works offline of the laptop.
7
  """
8
 
9
+ # ----------------------------------------------------------------------
10
+ # Monkey-patch gradio_client schema walker BEFORE importing gradio.
11
+ # Newer gradio_client (auto-installed by pip's resolution of gradio>=4.44)
12
+ # crashes at startup with `TypeError: argument of type 'bool' is not
13
+ # iterable` when it walks a schema with `additionalProperties: True`
14
+ # (which gr.JSON outputs produce). This brings the / route down and
15
+ # launch() then errors with "localhost is not accessible". Returning
16
+ # "Any" for bool schemas is what the unbroken upstream code does.
17
+ # ----------------------------------------------------------------------
18
+ import gradio_client.utils as _gc_utils # noqa: E402
19
+
20
+ _orig_get_type = _gc_utils.get_type
21
+ _orig_to_python = _gc_utils._json_schema_to_python_type
22
+
23
+
24
+ def _safe_get_type(schema):
25
+ if isinstance(schema, bool):
26
+ return "Any" if schema else "None"
27
+ return _orig_get_type(schema)
28
+
29
+
30
+ def _safe_to_python(schema, defs):
31
+ if isinstance(schema, bool):
32
+ return "Any" if schema else "None"
33
+ return _orig_to_python(schema, defs)
34
+
35
+
36
+ _gc_utils.get_type = _safe_get_type
37
+ _gc_utils._json_schema_to_python_type = _safe_to_python
38
 
39
  import json
40
  from pathlib import Path