Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ import tarfile
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
import requests
|
|
|
|
| 26 |
|
| 27 |
BASE = os.path.dirname(os.path.abspath(__file__))
|
| 28 |
if os.path.isdir("/data") and os.access("/data", os.W_OK):
|
|
@@ -330,6 +331,13 @@ def load_preset(name):
|
|
| 330 |
return s, m, q, o
|
| 331 |
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
CSS = """
|
| 334 |
.gradio-container { max-width: 900px !important; }
|
| 335 |
.bar textarea { font-family: monospace !important; white-space: pre !important; }
|
|
@@ -341,9 +349,11 @@ with gr.Blocks(title="Jev-style 判別式決策 POC") as demo:
|
|
| 341 |
"這就是 System 1 判別引擎:傳統 LLM Agent 每步 1–3 秒還可能寫壞 JSON,這裡一次前向傳播就給出完整機率分佈。\n\n"
|
| 342 |
"> ⏰ **首次啟動**需要下載模型(約 660MB),請看下方「後端狀態」等它就緒再按送出,之後啟動都是秒開。")
|
| 343 |
status_box = gr.Textbox(label="後端狀態", value="⏳ 後端準備中…", interactive=False)
|
|
|
|
| 344 |
with gr.Row():
|
| 345 |
preset = gr.Dropdown(list(PRESETS.keys()), label="範例一鍵填入", value="客服訊息分類")
|
| 346 |
refresh_btn = gr.Button("重新整理狀態", size="sm")
|
|
|
|
| 347 |
state = gr.Textbox(label="狀態文字(state)", lines=3)
|
| 348 |
mode = gr.Radio(["是非題", "多選題"], label="題型", value="多選題")
|
| 349 |
question = gr.Textbox(label="問題(instructions)", lines=1)
|
|
@@ -355,13 +365,14 @@ with gr.Blocks(title="Jev-style 判別式決策 POC") as demo:
|
|
| 355 |
|
| 356 |
preset.change(load_preset, preset, [state, mode, question, options])
|
| 357 |
refresh_btn.click(lambda: status_text(), outputs=status_box)
|
|
|
|
| 358 |
btn.click(decide, [state, mode, question, options],
|
| 359 |
[out_summary, out_bars, out_meta, status_box])
|
| 360 |
demo.load(load_preset, preset, [state, mode, question, options])
|
| 361 |
demo.load(lambda: status_text(), outputs=status_box)
|
| 362 |
|
| 363 |
if __name__ == "__main__":
|
| 364 |
-
print("[poc] app.py v20261003-
|
| 365 |
print(f"[poc] 資料目錄:{DATA}({'重啟後保留,可斷點續傳' if _DATA_PERSISTENT else '重啟後消失,請勿重啟'})", flush=True)
|
| 366 |
# Spaces 啟動時先備好後端(背景執行,不擋 UI)
|
| 367 |
ensure_backend_if_needed()
|
|
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
import requests
|
| 26 |
+
import spaces # ZeroGPU 執行期內建;不可寫進 requirements.txt(會蓋掉內建模組)
|
| 27 |
|
| 28 |
BASE = os.path.dirname(os.path.abspath(__file__))
|
| 29 |
if os.path.isdir("/data") and os.access("/data", os.W_OK):
|
|
|
|
| 331 |
return s, m, q, o
|
| 332 |
|
| 333 |
|
| 334 |
+
@spaces.GPU(duration=10)
|
| 335 |
+
def gpu_compat_check():
|
| 336 |
+
"""ZeroGPU 硬體要求至少一個 @spaces.GPU 函數才能啟動。
|
| 337 |
+
jevos 為純 CPU 運算(OpenVINO),此函數僅為通過啟動檢查的佔位,實際不參與判別、不消耗有意義的 GPU 配額。"""
|
| 338 |
+
return "ZeroGPU 相容檢查通過(判別運算實際於 CPU 執行)"
|
| 339 |
+
|
| 340 |
+
|
| 341 |
CSS = """
|
| 342 |
.gradio-container { max-width: 900px !important; }
|
| 343 |
.bar textarea { font-family: monospace !important; white-space: pre !important; }
|
|
|
|
| 349 |
"這就是 System 1 判別引擎:傳統 LLM Agent 每步 1–3 秒還可能寫壞 JSON,這裡一次前向傳播就給出完整機率分佈。\n\n"
|
| 350 |
"> ⏰ **首次啟動**需要下載模型(約 660MB),請看下方「後端狀態」等它就緒再按送出,之後啟動都是秒開。")
|
| 351 |
status_box = gr.Textbox(label="後端狀態", value="⏳ 後端準備中…", interactive=False)
|
| 352 |
+
gpu_out = gr.Textbox(label="ZeroGPU 相容檢查", value="", interactive=False)
|
| 353 |
with gr.Row():
|
| 354 |
preset = gr.Dropdown(list(PRESETS.keys()), label="範例一鍵填入", value="客服訊息分類")
|
| 355 |
refresh_btn = gr.Button("重新整理狀態", size="sm")
|
| 356 |
+
gpu_btn = gr.Button("GPU 相容檢查", size="sm")
|
| 357 |
state = gr.Textbox(label="狀態文字(state)", lines=3)
|
| 358 |
mode = gr.Radio(["是非題", "多選題"], label="題型", value="多選題")
|
| 359 |
question = gr.Textbox(label="問題(instructions)", lines=1)
|
|
|
|
| 365 |
|
| 366 |
preset.change(load_preset, preset, [state, mode, question, options])
|
| 367 |
refresh_btn.click(lambda: status_text(), outputs=status_box)
|
| 368 |
+
gpu_btn.click(gpu_compat_check, outputs=gpu_out)
|
| 369 |
btn.click(decide, [state, mode, question, options],
|
| 370 |
[out_summary, out_bars, out_meta, status_box])
|
| 371 |
demo.load(load_preset, preset, [state, mode, question, options])
|
| 372 |
demo.load(lambda: status_text(), outputs=status_box)
|
| 373 |
|
| 374 |
if __name__ == "__main__":
|
| 375 |
+
print("[poc] app.py v20261003-zerogpu (multi-source backend + @spaces.GPU)", flush=True)
|
| 376 |
print(f"[poc] 資料目錄:{DATA}({'重啟後保留,可斷點續傳' if _DATA_PERSISTENT else '重啟後消失,請勿重啟'})", flush=True)
|
| 377 |
# Spaces 啟動時先備好後端(背景執行,不擋 UI)
|
| 378 |
ensure_backend_if_needed()
|