Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -16,23 +16,41 @@ from transformers import (
|
|
| 16 |
)
|
| 17 |
|
| 18 |
# ============ GRADIO CLIENT COMPAT PATCH ============
|
| 19 |
-
#
|
| 20 |
-
#
|
| 21 |
-
#
|
| 22 |
try:
|
| 23 |
import gradio_client.utils as _grc_utils
|
| 24 |
|
| 25 |
if not getattr(_grc_utils, "_BOOL_SCHEMA_PATCHED", False):
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
def _safe_get_type(schema): # noqa: ANN001
|
| 29 |
if isinstance(schema, bool) or not isinstance(schema, dict):
|
| 30 |
-
|
| 31 |
-
|
| 32 |
return "any"
|
| 33 |
return _orig_get_type(schema)
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
_grc_utils._BOOL_SCHEMA_PATCHED = True
|
| 37 |
except Exception as _e:
|
| 38 |
# If gradio_client is unavailable or API changes, ignore and proceed.
|
|
@@ -44,15 +62,22 @@ def _launch_compat(demo, **kwargs):
|
|
| 44 |
Gradio ๋ฒ์ ๋ณ๋ก Blocks.launch() ์๊ทธ๋์ฒ๊ฐ ๋ฌ๋ผ์(์: ssr ์ง์ ์ฌ๋ถ),
|
| 45 |
ํ์ฌ ์ค์น๋ Gradio๊ฐ ์ง์ํ๋ ํค๋ง ๊ณจ๋ผ launch()๋ฅผ ํธ์ถํ๋ค.
|
| 46 |
"""
|
|
|
|
| 47 |
try:
|
| 48 |
-
sig = inspect.signature(demo.launch)
|
| 49 |
-
supported = set(sig.parameters.keys())
|
| 50 |
-
filtered = {k: v for k, v in kwargs.items() if k in supported}
|
| 51 |
-
return demo.launch(**filtered)
|
| 52 |
-
except Exception:
|
| 53 |
-
# signature introspection ์คํจ ์, ๋ณด์์ ์ผ๋ก ssr๋ง ์ ๊ฑฐ ํ ์ฌ์๋
|
| 54 |
-
kwargs.pop("ssr", None)
|
| 55 |
return demo.launch(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# ============ THEME SETUP ============
|
| 58 |
# Theme disabled to avoid API schema issues on HF Spaces
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
# ============ GRADIO CLIENT COMPAT PATCH ============
|
| 19 |
+
# Some gradio_client versions crash when encountering boolean JSON Schema nodes
|
| 20 |
+
# (e.g., additionalProperties: false/true) while generating /info API schema.
|
| 21 |
+
# Patch defensively to prevent startup failures on HF Spaces.
|
| 22 |
try:
|
| 23 |
import gradio_client.utils as _grc_utils
|
| 24 |
|
| 25 |
if not getattr(_grc_utils, "_BOOL_SCHEMA_PATCHED", False):
|
| 26 |
+
# 1) get_type() sometimes assumes schema is a dict
|
| 27 |
+
_orig_get_type = getattr(_grc_utils, "get_type", None)
|
| 28 |
|
| 29 |
def _safe_get_type(schema): # noqa: ANN001
|
| 30 |
if isinstance(schema, bool) or not isinstance(schema, dict):
|
| 31 |
+
return "any"
|
| 32 |
+
if _orig_get_type is None:
|
| 33 |
return "any"
|
| 34 |
return _orig_get_type(schema)
|
| 35 |
|
| 36 |
+
if _orig_get_type is not None:
|
| 37 |
+
_grc_utils.get_type = _safe_get_type
|
| 38 |
+
|
| 39 |
+
# 2) _json_schema_to_python_type() may raise on schema == True/False
|
| 40 |
+
_orig_js2pt = getattr(_grc_utils, "_json_schema_to_python_type", None)
|
| 41 |
+
|
| 42 |
+
def _safe_json_schema_to_python_type(schema, defs=None): # noqa: ANN001
|
| 43 |
+
if isinstance(schema, bool):
|
| 44 |
+
# boolean JSON Schema: True means "any", False means "no value".
|
| 45 |
+
# For API-info rendering, treating both as Any avoids crashes.
|
| 46 |
+
return "Any"
|
| 47 |
+
if _orig_js2pt is None:
|
| 48 |
+
return "Any"
|
| 49 |
+
return _orig_js2pt(schema, defs)
|
| 50 |
+
|
| 51 |
+
if _orig_js2pt is not None:
|
| 52 |
+
_grc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
|
| 53 |
+
|
| 54 |
_grc_utils._BOOL_SCHEMA_PATCHED = True
|
| 55 |
except Exception as _e:
|
| 56 |
# If gradio_client is unavailable or API changes, ignore and proceed.
|
|
|
|
| 62 |
Gradio ๋ฒ์ ๋ณ๋ก Blocks.launch() ์๊ทธ๋์ฒ๊ฐ ๋ฌ๋ผ์(์: ssr ์ง์ ์ฌ๋ถ),
|
| 63 |
ํ์ฌ ์ค์น๋ Gradio๊ฐ ์ง์ํ๋ ํค๋ง ๊ณจ๋ผ launch()๋ฅผ ํธ์ถํ๋ค.
|
| 64 |
"""
|
| 65 |
+
# ๋จผ์ ์ํ๋ ์ต์
์ผ๋ก ๊ทธ๋๋ก ํธ์ถํ๊ณ , "unexpected keyword"๊ฐ ๋๋ฉด ํด๋น ํค๋ง ์ ๊ฑฐ ํ ์ฌ์๋
|
| 66 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return demo.launch(**kwargs)
|
| 68 |
+
except TypeError as e:
|
| 69 |
+
msg = str(e)
|
| 70 |
+
if "unexpected keyword argument 'ssr'" in msg or 'unexpected keyword argument "ssr"' in msg:
|
| 71 |
+
kwargs.pop("ssr", None)
|
| 72 |
+
return demo.launch(**kwargs)
|
| 73 |
+
# ๊ทธ ์ธ ์ผ์ด์ค๋ ์๊ทธ๋์ฒ ๊ธฐ๋ฐ์ผ๋ก ํ ๋ฒ ๋ ๋ณด์์ ์ผ๋ก ํํฐ๋ง
|
| 74 |
+
try:
|
| 75 |
+
sig = inspect.signature(demo.launch)
|
| 76 |
+
supported = set(sig.parameters.keys())
|
| 77 |
+
filtered = {k: v for k, v in kwargs.items() if k in supported}
|
| 78 |
+
return demo.launch(**filtered)
|
| 79 |
+
except Exception:
|
| 80 |
+
raise
|
| 81 |
|
| 82 |
# ============ THEME SETUP ============
|
| 83 |
# Theme disabled to avoid API schema issues on HF Spaces
|