Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,13 +7,37 @@ from dotenv import load_dotenv
|
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
-
# ---- Gradio の API スキーマ生成を
|
| 11 |
try:
|
| 12 |
import gradio.blocks as _gr_blocks
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 のどちらでも拾えるように
|
| 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)):
|