justinhew commited on
Commit
e9655e8
·
1 Parent(s): 45c7380

Harden Gradio schema handling; rely on share=True for Spaces

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -7,10 +7,6 @@ import sys
7
  # Detect if running on Hugging Face Spaces
8
  IS_SPACE = os.getenv("SPACE_ID") is not None
9
 
10
- if IS_SPACE:
11
- # Disable API info generation to avoid schema parsing issues
12
- os.environ["GRADIO_DISABLE_API_INFO"] = "1"
13
-
14
  if not IS_SPACE:
15
  # Local configuration only
16
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
@@ -29,11 +25,20 @@ if not IS_SPACE:
29
  import gradio
30
  gradio.version_check = lambda: None # Disable version check
31
  try:
32
- import gradio.routes as gr_routes
33
- import gradio.blocks as gr_blocks
 
 
 
 
 
 
 
 
 
 
34
 
35
- gr_routes.api_info = lambda *args, **kwargs: {}
36
- gr_blocks.Blocks.get_api_info = lambda self: {} # type: ignore
37
  except Exception:
38
  pass
39
 
 
7
  # Detect if running on Hugging Face Spaces
8
  IS_SPACE = os.getenv("SPACE_ID") is not None
9
 
 
 
 
 
10
  if not IS_SPACE:
11
  # Local configuration only
12
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
 
25
  import gradio
26
  gradio.version_check = lambda: None # Disable version check
27
  try:
28
+ # Make schema-to-python conversion tolerant of booleans or other unexpected shapes
29
+ import gradio_client.utils as grc_utils
30
+
31
+ _orig_json_schema_to_python_type = grc_utils.json_schema_to_python_type
32
+
33
+ def _safe_json_schema_to_python_type(schema, defs=None):
34
+ if isinstance(schema, bool):
35
+ return "any"
36
+ try:
37
+ return _orig_json_schema_to_python_type(schema, defs)
38
+ except Exception:
39
+ return "any"
40
 
41
+ grc_utils.json_schema_to_python_type = _safe_json_schema_to_python_type
 
42
  except Exception:
43
  pass
44