amitlals
commited on
Commit
·
ea0e2da
1
Parent(s):
fe595e8
Patch gradio_client schema parser with try/catch fallback
Browse files- app_gradio.py +13 -10
app_gradio.py
CHANGED
|
@@ -47,25 +47,28 @@ def _ensure_hf_folder_compat():
|
|
| 47 |
|
| 48 |
|
| 49 |
def _patch_gradio_client_schema_bug():
|
| 50 |
-
"""Patch gradio_client's JSON schema parser to handle boolean
|
| 51 |
try:
|
| 52 |
from gradio_client import utils as client_utils
|
| 53 |
except (ImportError, AttributeError):
|
| 54 |
return
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
return
|
| 59 |
|
| 60 |
-
def
|
| 61 |
-
"""
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
return str
|
| 66 |
-
return original_get_type(schema)
|
| 67 |
|
| 68 |
-
client_utils.
|
| 69 |
|
| 70 |
|
| 71 |
_ensure_hf_folder_compat()
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
def _patch_gradio_client_schema_bug():
|
| 50 |
+
"""Patch gradio_client's JSON schema parser to handle boolean schemas."""
|
| 51 |
try:
|
| 52 |
from gradio_client import utils as client_utils
|
| 53 |
except (ImportError, AttributeError):
|
| 54 |
return
|
| 55 |
|
| 56 |
+
# Patch json_schema_to_python_type to catch and handle the error
|
| 57 |
+
original_json_to_type = getattr(
|
| 58 |
+
client_utils, 'json_schema_to_python_type', None
|
| 59 |
+
)
|
| 60 |
+
if not original_json_to_type:
|
| 61 |
return
|
| 62 |
|
| 63 |
+
def patched_json_to_type(schema, defs=None):
|
| 64 |
+
"""Safely handle JSON schema parsing for boolean schemas."""
|
| 65 |
+
try:
|
| 66 |
+
return original_json_to_type(schema, defs)
|
| 67 |
+
except Exception:
|
| 68 |
+
# If schema parsing fails (e.g., boolean schema), return str
|
| 69 |
return str
|
|
|
|
| 70 |
|
| 71 |
+
client_utils.json_schema_to_python_type = patched_json_to_type
|
| 72 |
|
| 73 |
|
| 74 |
_ensure_hf_folder_compat()
|