# Comprehensive patch for Gradio's boolean schema handling issues | |
import sys | |
def patch_gradio(): | |
try: | |
import gradio_client.utils | |
# Store the original functions | |
original_get_type = gradio_client.utils.get_type | |
original_json_schema_to_python_type = gradio_client.utils._json_schema_to_python_type | |
# Create a fixed version of get_type that handles booleans | |
def patched_get_type(schema): | |
if isinstance(schema, bool): | |
return "bool" | |
return original_get_type(schema) | |
# Create a fixed version of _json_schema_to_python_type that handles booleans | |
def patched_json_schema_to_python_type(schema, defs=None): | |
if isinstance(schema, bool): | |
return "bool" | |
return original_json_schema_to_python_type(schema, defs) | |
# Replace the original functions with our patched versions | |
gradio_client.utils.get_type = patched_get_type | |
gradio_client.utils._json_schema_to_python_type = patched_json_schema_to_python_type | |
print("β Enhanced Gradio patch applied successfully") | |
except ImportError: | |
print("β Could not import gradio_client.utils to apply patch") | |
except Exception as e: | |
print(f"β Failed to apply Gradio patch: {str(e)}") | |
# Apply the patch immediately when this module is imported | |
patch_gradio() |