Patch gradio_client schema walker
Browse files
app.py
CHANGED
|
@@ -14,7 +14,34 @@ Model weights, classes, and recall-constrained cutoffs for the baseline are
|
|
| 14 |
pulled from the HF model repo ``Pybunny/nilmbench-faustine`` at startup.
|
| 15 |
"""
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
import importlib.util
|
| 20 |
import json
|
|
|
|
| 14 |
pulled from the HF model repo ``Pybunny/nilmbench-faustine`` at startup.
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
# ----------------------------------------------------------------------
|
| 18 |
+
# Monkey-patch the gradio_client schema walker BEFORE importing gradio.
|
| 19 |
+
# In gradio 4.44 / gradio_client 1.5 the walker recurses into
|
| 20 |
+
# ``additionalProperties`` without checking whether the value is a bool
|
| 21 |
+
# (JSON-Schema allows ``additionalProperties: true``), then crashes with
|
| 22 |
+
# ``TypeError: argument of type 'bool' is not iterable``. This brings down
|
| 23 |
+
# the / route at startup. Patching the two entry points is enough.
|
| 24 |
+
# ----------------------------------------------------------------------
|
| 25 |
+
import gradio_client.utils as _gc_utils # noqa: E402
|
| 26 |
+
|
| 27 |
+
_orig_get_type = _gc_utils.get_type
|
| 28 |
+
_orig_to_python = _gc_utils._json_schema_to_python_type
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _safe_get_type(schema):
|
| 32 |
+
if isinstance(schema, bool):
|
| 33 |
+
return "Any" if schema else "None"
|
| 34 |
+
return _orig_get_type(schema)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _safe_to_python(schema, defs):
|
| 38 |
+
if isinstance(schema, bool):
|
| 39 |
+
return "Any" if schema else "None"
|
| 40 |
+
return _orig_to_python(schema, defs)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
_gc_utils.get_type = _safe_get_type
|
| 44 |
+
_gc_utils._json_schema_to_python_type = _safe_to_python
|
| 45 |
|
| 46 |
import importlib.util
|
| 47 |
import json
|