Spaces:
Sleeping
Sleeping
fix(deploy): monkey-patch gradio_client schema parsing bug where boolean additionalProperties throws TypeError
Browse files
app/services/plate_recognition.py
CHANGED
|
@@ -134,6 +134,21 @@ def run_pipeline_remote(*, image_bytes: bytes, filename: Optional[str] = None, c
|
|
| 134 |
from gradio_client import Client, handle_file
|
| 135 |
except ImportError:
|
| 136 |
raise HTTPException(status_code=500, detail="gradio_client is not installed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
|
| 138 |
tmp.write(image_bytes)
|
| 139 |
tmp_path = tmp.name
|
|
|
|
| 134 |
from gradio_client import Client, handle_file
|
| 135 |
except ImportError:
|
| 136 |
raise HTTPException(status_code=500, detail="gradio_client is not installed.")
|
| 137 |
+
|
| 138 |
+
# Monkey-patch gradio_client schema parsing bug where boolean additionalProperties throws TypeError
|
| 139 |
+
try:
|
| 140 |
+
import gradio_client.utils
|
| 141 |
+
_orig_parser = gradio_client.utils._json_schema_to_python_type
|
| 142 |
+
if not hasattr(gradio_client.utils, "_safe_parser_applied"):
|
| 143 |
+
def _safe_parser(schema, defs):
|
| 144 |
+
if isinstance(schema, bool) or not isinstance(schema, dict):
|
| 145 |
+
return "Any"
|
| 146 |
+
return _orig_parser(schema, defs)
|
| 147 |
+
gradio_client.utils._json_schema_to_python_type = _safe_parser
|
| 148 |
+
gradio_client.utils._safe_parser_applied = True
|
| 149 |
+
except Exception:
|
| 150 |
+
pass
|
| 151 |
+
|
| 152 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
|
| 153 |
tmp.write(image_bytes)
|
| 154 |
tmp_path = tmp.name
|