Download patch_gradio.py from umarbalak/QueryMind: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/umarbalak/QueryMind/resolve/main/patch_gradio.py
- Command line
-
hf download hf://spaces/umarbalak/QueryMind/patch_gradio.py
-
curl -L -o patch_gradio.py https://huggingface.co/spaces/umarbalak/QueryMind/resolve/main/patch_gradio.py
1.28 kB
| 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 |