CodeChamp95 commited on
Commit
e3044ac
Β·
verified Β·
1 Parent(s): c9f1134

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -5,15 +5,6 @@ import os
5
  os.environ.pop("GRADIO_HOT_RELOAD", None)
6
  import gradio as gr
7
 
8
- # ── Patch the broken gradio_client JSON-schema parser ────────────────────────
9
- # gradio/routes.py calls `app.get_blocks().get_api_info()` on every /info
10
- # request. gradio_client.utils._json_schema_to_python_type crashes when
11
- # `additionalProperties` is a plain bool (True/False) instead of a dict,
12
- # raising "TypeError: argument of type 'bool' is not iterable".
13
- # We silence it by making get_api_info() return an empty dict instead.
14
- import gradio.blocks as _gr_blocks
15
- _gr_blocks.Blocks.get_api_info = lambda self, *a, **kw: {}
16
-
17
  # ── Patch for Starlette 1.0.0 TemplateResponse signature change ──────────────
18
  import starlette.templating
19
 
@@ -33,6 +24,33 @@ def _patched_template_response(self, *args, **kwargs):
33
  starlette.templating.Jinja2Templates.TemplateResponse = _patched_template_response
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  import pandas as pd
37
  import json
38
  from pathlib import Path
 
5
  os.environ.pop("GRADIO_HOT_RELOAD", None)
6
  import gradio as gr
7
 
 
 
 
 
 
 
 
 
 
8
  # ── Patch for Starlette 1.0.0 TemplateResponse signature change ──────────────
9
  import starlette.templating
10
 
 
24
  starlette.templating.Jinja2Templates.TemplateResponse = _patched_template_response
25
 
26
 
27
+ # ── Patch the gradio_client JSON-schema parser crash safely ──────────────────
28
+ import gradio.blocks as _gr_blocks
29
+
30
+ _original_get_api_info = _gr_blocks.Blocks.get_api_info
31
+
32
+ def _safe_get_api_info(self, *args, **kwargs):
33
+ # 1. Get the actual API routing map
34
+ api_info = _original_get_api_info(self, *args, **kwargs)
35
+
36
+ # 2. Recursively scrub boolean `additionalProperties`
37
+ def fix_schema_booleans(obj):
38
+ if isinstance(obj, dict):
39
+ if "additionalProperties" in obj and isinstance(obj["additionalProperties"], bool):
40
+ # Replace the boolean with an empty dict to prevent the iterable crash
41
+ obj["additionalProperties"] = {}
42
+ for k, v in obj.items():
43
+ fix_schema_booleans(v)
44
+ elif isinstance(obj, list):
45
+ for item in obj:
46
+ fix_schema_booleans(item)
47
+
48
+ fix_schema_booleans(api_info)
49
+ return api_info
50
+
51
+ _gr_blocks.Blocks.get_api_info = _safe_get_api_info
52
+
53
+
54
  import pandas as pd
55
  import json
56
  from pathlib import Path