amitlals commited on
Commit
ea0e2da
·
1 Parent(s): fe595e8

Patch gradio_client schema parser with try/catch fallback

Browse files
Files changed (1) hide show
  1. app_gradio.py +13 -10
app_gradio.py CHANGED
@@ -47,25 +47,28 @@ def _ensure_hf_folder_compat():
47
 
48
 
49
  def _patch_gradio_client_schema_bug():
50
- """Patch gradio_client's JSON schema parser to handle boolean schema values."""
51
  try:
52
  from gradio_client import utils as client_utils
53
  except (ImportError, AttributeError):
54
  return
55
 
56
- original_get_type = getattr(client_utils, 'get_type', None)
57
- if not original_get_type:
 
 
 
58
  return
59
 
60
- def patched_get_type(schema):
61
- """Wrapper that handles the case where schema is a boolean."""
62
- if isinstance(schema, bool):
63
- # If schema is True, it matches anything; if False, it matches nothing
64
- # Return str as a safe default
 
65
  return str
66
- return original_get_type(schema)
67
 
68
- client_utils.get_type = patched_get_type
69
 
70
 
71
  _ensure_hf_folder_compat()
 
47
 
48
 
49
  def _patch_gradio_client_schema_bug():
50
+ """Patch gradio_client's JSON schema parser to handle boolean schemas."""
51
  try:
52
  from gradio_client import utils as client_utils
53
  except (ImportError, AttributeError):
54
  return
55
 
56
+ # Patch json_schema_to_python_type to catch and handle the error
57
+ original_json_to_type = getattr(
58
+ client_utils, 'json_schema_to_python_type', None
59
+ )
60
+ if not original_json_to_type:
61
  return
62
 
63
+ def patched_json_to_type(schema, defs=None):
64
+ """Safely handle JSON schema parsing for boolean schemas."""
65
+ try:
66
+ return original_json_to_type(schema, defs)
67
+ except Exception:
68
+ # If schema parsing fails (e.g., boolean schema), return str
69
  return str
 
70
 
71
+ client_utils.json_schema_to_python_type = patched_json_to_type
72
 
73
 
74
  _ensure_hf_folder_compat()