Corin1998 commited on
Commit
9d748bc
·
verified ·
1 Parent(s): 5c349c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -7,13 +7,37 @@ from dotenv import load_dotenv
7
 
8
  load_dotenv()
9
 
10
- # ---- Gradio の API スキーマ生成を無効して 500 を回避(既知バグ対策)----
11
  try:
12
  import gradio.blocks as _gr_blocks
13
- def _no_api_info(self):
14
- # API 情報は不要なので空を返す(UI には影響なし)
15
- return {}
16
- _gr_blocks.Blocks.get_api_info = _no_api_info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  except Exception as _e:
18
  print("[warn] failed to patch gradio Blocks.get_api_info:", _e, flush=True)
19
  # -------------------------------------------------------------------------
@@ -57,7 +81,7 @@ def ui_company_score_and_proposal(company_name,
57
 
58
  urls = [u.strip() for u in (urls_text or "").splitlines() if u.strip()]
59
 
60
- # gr.File or str のどちらでも拾えるように安全化(multiple=False も考慮
61
  try:
62
  iterable = files or []
63
  if not isinstance(iterable, (list, tuple)):
 
7
 
8
  load_dotenv()
9
 
10
+ # ---- Gradio の API スキーマ生成を安全化(既知バグ対策)----
11
  try:
12
  import gradio.blocks as _gr_blocks
13
+
14
+ _orig_get_api_info = _gr_blocks.Blocks.get_api_info
15
+
16
+ def _sanitize_json_schema(obj):
17
+ # additionalProperties が True/False だと gradio_client 側で TypeError になるため {} に変換
18
+ if isinstance(obj, dict):
19
+ out = {}
20
+ for k, v in obj.items():
21
+ if k == "additionalProperties" and isinstance(v, bool):
22
+ out[k] = {}
23
+ else:
24
+ out[k] = _sanitize_json_schema(v)
25
+ return out
26
+ elif isinstance(obj, list):
27
+ return [_sanitize_json_schema(x) for x in obj]
28
+ else:
29
+ return obj
30
+
31
+ def _safe_get_api_info(self):
32
+ try:
33
+ info = _orig_get_api_info(self)
34
+ return _sanitize_json_schema(info)
35
+ except Exception as e:
36
+ print("[warn] Blocks.get_api_info failed; returning minimal schema:", e, flush=True)
37
+ # フロントが参照する最小限の構造だけ返す
38
+ return {"named_endpoints": {}, "unnamed_endpoints": []}
39
+
40
+ _gr_blocks.Blocks.get_api_info = _safe_get_api_info
41
  except Exception as _e:
42
  print("[warn] failed to patch gradio Blocks.get_api_info:", _e, flush=True)
43
  # -------------------------------------------------------------------------
 
81
 
82
  urls = [u.strip() for u in (urls_text or "").splitlines() if u.strip()]
83
 
84
+ # gr.File or str のどちらでも拾えるように(multiple=False の単体ケース吸収
85
  try:
86
  iterable = files or []
87
  if not isinstance(iterable, (list, tuple)):