Spaces:
Sleeping
Sleeping
Add ZeroGPU heartbeat + clean gradio 6 launch kwargs
Browse files
app.py
CHANGED
|
@@ -47,16 +47,43 @@ PUSH_MODES = {
|
|
| 47 |
|
| 48 |
MAX_SPLIT_NAME_LEN = 96
|
| 49 |
|
| 50 |
-
#: Gradio 6 đổi `show_copy_button` -> `buttons`; giữ tương thích cả Gradio 5 và 6.
|
| 51 |
-
GRADIO_MAJOR = int(str(getattr(gr, "__version__", "5")).split(".")[0])
|
| 52 |
-
COPY_BUTTON_KWARGS = {"buttons": ["copy"]} if GRADIO_MAJOR >= 6 else {"show_copy_button": True}
|
| 53 |
-
|
| 54 |
CSS = """
|
| 55 |
.gradio-container {max-width: 1180px !important;}
|
| 56 |
#extract-btn {min-height: 52px; font-size: 1.05rem; font-weight: 600;}
|
| 57 |
#log-box textarea {font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem;}
|
| 58 |
"""
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# ---------------------------------------------------------------------------
|
| 62 |
# Tiện ích
|
|
@@ -622,7 +649,7 @@ def extract_and_push(
|
|
| 622 |
# Giao diện
|
| 623 |
# ---------------------------------------------------------------------------
|
| 624 |
|
| 625 |
-
with gr.Blocks(
|
| 626 |
gr.Markdown(
|
| 627 |
"""
|
| 628 |
# 🧲 Text Column Extract
|
|
@@ -807,4 +834,4 @@ with gr.Blocks(title="Text Column Extract", theme=gr.themes.Soft(), css=CSS) as
|
|
| 807 |
|
| 808 |
|
| 809 |
if __name__ == "__main__":
|
| 810 |
-
demo.queue(max_size=16, default_concurrency_limit=1).launch(
|
|
|
|
| 47 |
|
| 48 |
MAX_SPLIT_NAME_LEN = 96
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
CSS = """
|
| 51 |
.gradio-container {max-width: 1180px !important;}
|
| 52 |
#extract-btn {min-height: 52px; font-size: 1.05rem; font-weight: 600;}
|
| 53 |
#log-box textarea {font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem;}
|
| 54 |
"""
|
| 55 |
|
| 56 |
+
#: Gradio 6 đổi `show_copy_button` -> `buttons`; giữ tương thích cả Gradio 5 và 6.
|
| 57 |
+
GRADIO_MAJOR = int(str(getattr(gr, "__version__", "5")).split(".")[0])
|
| 58 |
+
COPY_BUTTON_KWARGS = {"buttons": ["copy"]} if GRADIO_MAJOR >= 6 else {"show_copy_button": True}
|
| 59 |
+
|
| 60 |
+
#: Gradio 6 chuyển `theme`/`css` từ Blocks sang launch().
|
| 61 |
+
BLOCKS_KWARGS: dict = {"title": "Text Column Extract"}
|
| 62 |
+
LAUNCH_KWARGS: dict = {"show_error": True}
|
| 63 |
+
if GRADIO_MAJOR >= 6:
|
| 64 |
+
LAUNCH_KWARGS.update(theme=gr.themes.Soft(), css=CSS)
|
| 65 |
+
else:
|
| 66 |
+
BLOCKS_KWARGS.update(theme=gr.themes.Soft(), css=CSS)
|
| 67 |
+
|
| 68 |
+
# ---------------------------------------------------------------------------
|
| 69 |
+
# ZeroGPU
|
| 70 |
+
# ---------------------------------------------------------------------------
|
| 71 |
+
# Space này chạy trên hardware ZeroGPU (mức miễn phí cho tài khoản cá nhân).
|
| 72 |
+
# ZeroGPU yêu cầu app phải có ít nhất một hàm gắn `@spaces.GPU` lúc khởi động,
|
| 73 |
+
# nếu không sẽ báo "No @spaces.GPU function detected during startup".
|
| 74 |
+
# App chỉ dùng CPU nên đây chỉ là một hàm "heartbeat" không được gọi từ UI;
|
| 75 |
+
# theo tài liệu ZeroGPU, decorator này là no-op ngoài môi trường ZeroGPU.
|
| 76 |
+
try: # pragma: no cover
|
| 77 |
+
import spaces # type: ignore
|
| 78 |
+
|
| 79 |
+
@spaces.GPU
|
| 80 |
+
def _zerogpu_heartbeat() -> str:
|
| 81 |
+
"""Chỉ để thoả yêu cầu khởi động của ZeroGPU — không gọi từ UI."""
|
| 82 |
+
return "ok"
|
| 83 |
+
|
| 84 |
+
except Exception: # noqa: BLE001 - môi trường không có ZeroGPU thì bỏ qua
|
| 85 |
+
pass
|
| 86 |
+
|
| 87 |
|
| 88 |
# ---------------------------------------------------------------------------
|
| 89 |
# Tiện ích
|
|
|
|
| 649 |
# Giao diện
|
| 650 |
# ---------------------------------------------------------------------------
|
| 651 |
|
| 652 |
+
with gr.Blocks(**BLOCKS_KWARGS) as demo:
|
| 653 |
gr.Markdown(
|
| 654 |
"""
|
| 655 |
# 🧲 Text Column Extract
|
|
|
|
| 834 |
|
| 835 |
|
| 836 |
if __name__ == "__main__":
|
| 837 |
+
demo.queue(max_size=16, default_concurrency_limit=1).launch(**LAUNCH_KWARGS)
|