amitlals
commited on
Commit
·
fe595e8
1
Parent(s):
33119bf
Add gradio_client schema bug patch to handle boolean schema values
Browse files- app_gradio.py +23 -0
app_gradio.py
CHANGED
|
@@ -46,7 +46,30 @@ def _ensure_hf_folder_compat():
|
|
| 46 |
hub_module.HfFolder = _CompatHfFolder
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
_ensure_hf_folder_compat()
|
|
|
|
| 50 |
|
| 51 |
import gradio as gr
|
| 52 |
print(f"Gradio version: {gr.__version__}")
|
|
|
|
| 46 |
hub_module.HfFolder = _CompatHfFolder
|
| 47 |
|
| 48 |
|
| 49 |
+
def _patch_gradio_client_schema_bug():
|
| 50 |
+
"""Patch gradio_client's JSON schema parser to handle boolean schema values."""
|
| 51 |
+
try:
|
| 52 |
+
from gradio_client import utils as client_utils
|
| 53 |
+
except (ImportError, AttributeError):
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
original_get_type = getattr(client_utils, 'get_type', None)
|
| 57 |
+
if not original_get_type:
|
| 58 |
+
return
|
| 59 |
+
|
| 60 |
+
def patched_get_type(schema):
|
| 61 |
+
"""Wrapper that handles the case where schema is a boolean."""
|
| 62 |
+
if isinstance(schema, bool):
|
| 63 |
+
# If schema is True, it matches anything; if False, it matches nothing
|
| 64 |
+
# Return str as a safe default
|
| 65 |
+
return str
|
| 66 |
+
return original_get_type(schema)
|
| 67 |
+
|
| 68 |
+
client_utils.get_type = patched_get_type
|
| 69 |
+
|
| 70 |
+
|
| 71 |
_ensure_hf_folder_compat()
|
| 72 |
+
_patch_gradio_client_schema_bug()
|
| 73 |
|
| 74 |
import gradio as gr
|
| 75 |
print(f"Gradio version: {gr.__version__}")
|