BoHuangLab commited on
Commit
485fb8a
·
verified ·
1 Parent(s): 060ee97

Fix 500 on /gradio_api/info: handle bool additionalProperties schemas

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -18,6 +18,28 @@ import pandas as pd
18
  import metrics
19
  import pipeline
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # ZeroGPU: only present on HF Spaces hardware, so the import is optional.
22
  try:
23
  import spaces
 
18
  import metrics
19
  import pipeline
20
 
21
+ # gradio_client walks component API schemas to build /gradio_api/info. JSON Schema
22
+ # allows `additionalProperties: true`, but the walker recurses into that bool as if
23
+ # it were a schema and then does `"const" in schema`, raising
24
+ # TypeError: argument of type 'bool' is not iterable
25
+ # which 500s /gradio_api/info -- the API panel and any gradio_client call -- while
26
+ # the UI itself keeps serving. Short-circuit bool schemas before they reach get_type().
27
+ # The recursive calls resolve this name through the module global, so rebinding it
28
+ # covers the nested case that actually triggers here.
29
+ try:
30
+ import gradio_client.utils as _gc_utils
31
+
32
+ _orig_schema_to_type = _gc_utils._json_schema_to_python_type
33
+
34
+ def _schema_to_type(schema, defs=None):
35
+ if isinstance(schema, bool):
36
+ return "Any" if schema else "None"
37
+ return _orig_schema_to_type(schema, defs)
38
+
39
+ _gc_utils._json_schema_to_python_type = _schema_to_type
40
+ except Exception as exc: # never let the shim take the app down
41
+ print(f"[startup] gradio_client schema patch skipped: {exc}")
42
+
43
  # ZeroGPU: only present on HF Spaces hardware, so the import is optional.
44
  try:
45
  import spaces