update
Browse files- patch_gradio.py +21 -10
patch_gradio.py
CHANGED
|
@@ -1,20 +1,31 @@
|
|
| 1 |
import gradio_client.utils
|
| 2 |
|
| 3 |
-
# Store the original function
|
| 4 |
-
|
| 5 |
|
| 6 |
# Define the patched function
|
| 7 |
-
def
|
| 8 |
try:
|
| 9 |
-
# Check if schema is a
|
| 10 |
-
if
|
| 11 |
-
return
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
return
|
| 15 |
except Exception as e:
|
| 16 |
print(f"Error parsing schema: {schema}, Error: {e}")
|
| 17 |
-
return "
|
| 18 |
|
| 19 |
# Apply the patch
|
| 20 |
-
gradio_client.utils.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio_client.utils
|
| 2 |
|
| 3 |
+
# Store the original function to maintain its behavior
|
| 4 |
+
original_json_schema_to_python_type = gradio_client.utils._json_schema_to_python_type
|
| 5 |
|
| 6 |
# Define the patched function
|
| 7 |
+
def patched_json_schema_to_python_type(schema, defs=None):
|
| 8 |
try:
|
| 9 |
+
# Check if schema is a boolean - handle this special case
|
| 10 |
+
if isinstance(schema, bool):
|
| 11 |
+
return "any" # Return a sensible default type for boolean schemas
|
| 12 |
|
| 13 |
+
# Continue with original function for non-boolean schemas
|
| 14 |
+
return original_json_schema_to_python_type(schema, defs)
|
| 15 |
except Exception as e:
|
| 16 |
print(f"Error parsing schema: {schema}, Error: {e}")
|
| 17 |
+
return "any" # Return a default type for invalid schemas
|
| 18 |
|
| 19 |
# Apply the patch
|
| 20 |
+
gradio_client.utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
| 21 |
+
|
| 22 |
+
# Also patch the wrapper function that calls the internal function
|
| 23 |
+
def patched_json_schema_to_python_type_wrapper(schema, defs=None):
|
| 24 |
+
try:
|
| 25 |
+
return patched_json_schema_to_python_type(schema, schema.get("$defs"))
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Error in wrapper: {e}")
|
| 28 |
+
return "any"
|
| 29 |
+
|
| 30 |
+
# Apply the wrapper patch
|
| 31 |
+
gradio_client.utils.json_schema_to_python_type = patched_json_schema_to_python_type_wrapper
|