Spaces:
Running
Running
prodya-dev commited on
Commit ·
e3055b5
1
Parent(s): 5790094
fix: also patch _json_schema_to_python_type for boolean JSON schema
Browse files
app.py
CHANGED
|
@@ -49,18 +49,26 @@ except ImportError:
|
|
| 49 |
pass
|
| 50 |
_hfh.HfFolder = _HfFolder
|
| 51 |
|
| 52 |
-
# 2. gradio_client.utils
|
| 53 |
-
#
|
| 54 |
-
#
|
| 55 |
-
#
|
| 56 |
try:
|
| 57 |
import gradio_client.utils as _gc_utils
|
|
|
|
| 58 |
_orig_get_type = _gc_utils.get_type # type: ignore[attr-defined]
|
| 59 |
def _patched_get_type(schema): # type: ignore[no-untyped-def]
|
| 60 |
if not isinstance(schema, dict):
|
| 61 |
return "Any"
|
| 62 |
return _orig_get_type(schema)
|
| 63 |
_gc_utils.get_type = _patched_get_type # type: ignore[attr-defined]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
except Exception:
|
| 65 |
pass
|
| 66 |
|
|
|
|
| 49 |
pass
|
| 50 |
_hfh.HfFolder = _HfFolder
|
| 51 |
|
| 52 |
+
# 2. gradio_client.utils doesn't guard against JSON Schema boolean values
|
| 53 |
+
# (True/False are valid JSON Schemas meaning "any" / "never").
|
| 54 |
+
# Two functions need patching: get_type() and _json_schema_to_python_type().
|
| 55 |
+
# Without these, startup health-check returns 500 → url_ok() → ValueError.
|
| 56 |
try:
|
| 57 |
import gradio_client.utils as _gc_utils
|
| 58 |
+
|
| 59 |
_orig_get_type = _gc_utils.get_type # type: ignore[attr-defined]
|
| 60 |
def _patched_get_type(schema): # type: ignore[no-untyped-def]
|
| 61 |
if not isinstance(schema, dict):
|
| 62 |
return "Any"
|
| 63 |
return _orig_get_type(schema)
|
| 64 |
_gc_utils.get_type = _patched_get_type # type: ignore[attr-defined]
|
| 65 |
+
|
| 66 |
+
_orig_j2p = _gc_utils._json_schema_to_python_type # type: ignore[attr-defined]
|
| 67 |
+
def _patched_j2p(schema, defs=None): # type: ignore[no-untyped-def]
|
| 68 |
+
if not isinstance(schema, dict):
|
| 69 |
+
return "Any"
|
| 70 |
+
return _orig_j2p(schema, defs)
|
| 71 |
+
_gc_utils._json_schema_to_python_type = _patched_j2p # type: ignore[attr-defined]
|
| 72 |
except Exception:
|
| 73 |
pass
|
| 74 |
|