github-actions[bot] commited on
Commit
960e045
·
1 Parent(s): c5ece02

Deploy from GitHub - 2026-01-21 07:16:40

Browse files
Files changed (1) hide show
  1. app.py +14 -41
app.py CHANGED
@@ -15,53 +15,26 @@ https://arxiv.org/abs/1603.08155
15
  """
16
 
17
  # ============================================================================
18
- # PATCH gradio_client BEFORE importing gradio
19
- # This fixes a bug where schema can be a bool (False means "any type")
20
  # ============================================================================
21
  import sys
22
 
 
 
 
 
 
 
23
  def _patched_get_type(schema):
24
- """Patched version that handles when schema is a bool (False for any type)"""
 
25
  if isinstance(schema, bool):
26
  return "Any" if not schema else "bool"
27
- if not isinstance(schema, dict):
28
- return str(type(schema).__name__)
29
- if "const" in schema:
30
- return f"Literal[{repr(schema['const'])}]"
31
- if "enum" in schema:
32
- return f"Literal[{', '.join(repr(v) for v in schema['enum'])}]"
33
- if "$ref" in schema:
34
- ref = schema["$ref"]
35
- if ref.startswith("#/$defs/"):
36
- return ref.split("/")[-1]
37
- return ref
38
- if "type" in schema:
39
- t = schema["type"]
40
- if t == "string":
41
- return "str"
42
- elif t == "number":
43
- return "float"
44
- elif t == "integer":
45
- return "int"
46
- elif t == "boolean":
47
- return "bool"
48
- elif t == "array":
49
- if "items" in schema:
50
- items_type = _patched_get_type(schema["items"])
51
- return f"list[{items_type}]"
52
- return "list"
53
- elif t == "object":
54
- if "additionalProperties" in schema:
55
- items_type = _patched_get_type(schema["additionalProperties"])
56
- return f"dict[str, {items_type}]"
57
- return "dict"
58
- return "Any"
59
-
60
- # Pre-patch by installing in sys.modules before gradio imports it
61
- import types
62
- mock_client_utils = types.ModuleType('gradio_client.utils')
63
- mock_client_utils.get_type = _patched_get_type
64
- sys.modules['gradio_client.utils'] = mock_client_utils
65
 
66
  # Now safe to import gradio
67
  import gradio as gr
 
15
  """
16
 
17
  # ============================================================================
18
+ # PATCH gradio_client to fix bool schema bug
 
19
  # ============================================================================
20
  import sys
21
 
22
+ # First import the real module to get all its contents
23
+ import gradio_client.utils as _real_client_utils
24
+
25
+ # Save the original get_type function
26
+ _original_get_type = _real_client_utils.get_type
27
+
28
  def _patched_get_type(schema):
29
+ """Patched version that handles when schema is a bool (False means "any type")"""
30
+ # Fix the bug: check if schema is a bool before trying "in" operator
31
  if isinstance(schema, bool):
32
  return "Any" if not schema else "bool"
33
+ # Call original for everything else
34
+ return _original_get_type(schema)
35
+
36
+ # Replace the function
37
+ _real_client_utils.get_type = _patched_get_type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  # Now safe to import gradio
40
  import gradio as gr