Spaces:
Running
Running
Ziyang Wang commited on
Commit ·
0385d22
1
Parent(s): 483161e
also patch _json_schema_to_python_type for bool schemas
Browse files
app.py
CHANGED
|
@@ -11,10 +11,11 @@ import os
|
|
| 11 |
|
| 12 |
# Workaround for a long-standing gradio_client bug that hits the /info endpoint
|
| 13 |
# when any component emits a JSON schema with `additionalProperties: True/False`
|
| 14 |
-
# (a plain bool). get_type()
|
| 15 |
-
#
|
| 16 |
-
#
|
| 17 |
import gradio_client.utils as _gcu
|
|
|
|
| 18 |
_orig_get_type = _gcu.get_type
|
| 19 |
def _safe_get_type(schema):
|
| 20 |
if not isinstance(schema, dict):
|
|
@@ -22,6 +23,14 @@ def _safe_get_type(schema):
|
|
| 22 |
return _orig_get_type(schema)
|
| 23 |
_gcu.get_type = _safe_get_type
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
import gradio as gr
|
| 26 |
import pandas as pd
|
| 27 |
|
|
|
|
| 11 |
|
| 12 |
# Workaround for a long-standing gradio_client bug that hits the /info endpoint
|
| 13 |
# when any component emits a JSON schema with `additionalProperties: True/False`
|
| 14 |
+
# (a plain bool). Both get_type() and _json_schema_to_python_type() assume the
|
| 15 |
+
# schema is a dict and crash on bools. Patch both before Gradio loads its
|
| 16 |
+
# FastAPI routes.
|
| 17 |
import gradio_client.utils as _gcu
|
| 18 |
+
|
| 19 |
_orig_get_type = _gcu.get_type
|
| 20 |
def _safe_get_type(schema):
|
| 21 |
if not isinstance(schema, dict):
|
|
|
|
| 23 |
return _orig_get_type(schema)
|
| 24 |
_gcu.get_type = _safe_get_type
|
| 25 |
|
| 26 |
+
_orig_json_schema = _gcu._json_schema_to_python_type
|
| 27 |
+
def _safe_json_schema(schema, defs=None):
|
| 28 |
+
if not isinstance(schema, dict):
|
| 29 |
+
# `additionalProperties: True` → accepts anything; `False` → accepts nothing.
|
| 30 |
+
return "Any" if schema else "None"
|
| 31 |
+
return _orig_json_schema(schema, defs)
|
| 32 |
+
_gcu._json_schema_to_python_type = _safe_json_schema
|
| 33 |
+
|
| 34 |
import gradio as gr
|
| 35 |
import pandas as pd
|
| 36 |
|