umarbalak commited on
Commit
0e3d491
·
1 Parent(s): f05aaf5
Files changed (1) hide show
  1. 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
- original_get_type = gradio_client.utils.get_type
5
 
6
  # Define the patched function
7
- def patched_get_type(schema):
8
  try:
9
- # Check if schema is a dict before using 'in' operator
10
- if not isinstance(schema, dict):
11
- return str(schema) # Convert to string as fallback
12
 
13
- # Original logic continues
14
- return original_get_type(schema)
15
  except Exception as e:
16
  print(f"Error parsing schema: {schema}, Error: {e}")
17
- return "unknown" # Return a default type for invalid schemas
18
 
19
  # Apply the patch
20
- gradio_client.utils.get_type = patched_get_type
 
 
 
 
 
 
 
 
 
 
 
 
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