drozdgk commited on
Commit
52f5401
·
1 Parent(s): e7e26ca

fix: patch gradio_client bool-schema crash (/api_info)

Browse files
Files changed (2) hide show
  1. app.py +18 -0
  2. mvp.py +16 -0
app.py CHANGED
@@ -4,6 +4,24 @@ import gradio as gr
4
 
5
 
6
  def _launch():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # HF Spaces expects the app to listen on 0.0.0.0:7860 (PORT may be provided).
8
  import mvp
9
 
 
4
 
5
 
6
  def _launch():
7
+ # HF Spaces/Gradio sometimes calls /api_info regardless of `show_api=False`.
8
+ # Some gradio_client versions crash when JSON schema uses boolean `additionalProperties`.
9
+ # Patch defensively to avoid bringing down the whole app.
10
+ try:
11
+ import gradio_client.utils as _gcu
12
+
13
+ if hasattr(_gcu, "_json_schema_to_python_type"):
14
+ _orig = _gcu._json_schema_to_python_type
15
+
16
+ def _json_schema_to_python_type_patched(schema, defs=None):
17
+ if isinstance(schema, bool):
18
+ return "Any"
19
+ return _orig(schema, defs)
20
+
21
+ _gcu._json_schema_to_python_type = _json_schema_to_python_type_patched
22
+ except Exception:
23
+ pass
24
+
25
  # HF Spaces expects the app to listen on 0.0.0.0:7860 (PORT may be provided).
26
  import mvp
27
 
mvp.py CHANGED
@@ -29,6 +29,22 @@ try:
29
  except Exception:
30
  gdown = None
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
33
  sys.path.append(os.path.join(REPO_ROOT, "vggt"))
34
  MK_PATH = os.path.join(REPO_ROOT, "MaskClustering")
 
29
  except Exception:
30
  gdown = None
31
 
32
+ # Defensive patch: some gradio_client versions crash on JSON schema with boolean additionalProperties.
33
+ try:
34
+ import gradio_client.utils as _gcu
35
+
36
+ if hasattr(_gcu, "_json_schema_to_python_type"):
37
+ _orig = _gcu._json_schema_to_python_type
38
+
39
+ def _json_schema_to_python_type_patched(schema, defs=None):
40
+ if isinstance(schema, bool):
41
+ return "Any"
42
+ return _orig(schema, defs)
43
+
44
+ _gcu._json_schema_to_python_type = _json_schema_to_python_type_patched
45
+ except Exception:
46
+ pass
47
+
48
  REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
49
  sys.path.append(os.path.join(REPO_ROOT, "vggt"))
50
  MK_PATH = os.path.join(REPO_ROOT, "MaskClustering")