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