Spaces:
Sleeping
Sleeping
Commit ·
fbd137e
1
Parent(s): cff9165
Add Hugging Face config files to subfolder
Browse files
app.py
CHANGED
|
@@ -469,10 +469,15 @@ if __name__ == "__main__":
|
|
| 469 |
|
| 470 |
if is_hf:
|
| 471 |
print("偵測到為 Hugging Face Spaces 雲端環境,使用 Gradio 官方 launch() 啟動以相容 ZeroGPU 端口轉發與生命週期...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
demo.launch(
|
| 473 |
server_name="0.0.0.0",
|
| 474 |
server_port=7860,
|
| 475 |
-
prevent_thread_lock=False
|
|
|
|
| 476 |
)
|
| 477 |
else:
|
| 478 |
import uvicorn
|
|
|
|
| 469 |
|
| 470 |
if is_hf:
|
| 471 |
print("偵測到為 Hugging Face Spaces 雲端環境,使用 Gradio 官方 launch() 啟動以相容 ZeroGPU 端口轉發與生命週期...")
|
| 472 |
+
# ⚠️ 必須將 ssr_mode 設為 False!
|
| 473 |
+
# 在 Gradio 5/6 中,預設啟用的 SSR 模式會另外啟動一個 Node.js 代理伺服器來攔截請求,
|
| 474 |
+
# 這會導致我們自訂的 FastAPI /docs、/predict、/train 等 API 端點被 Node.js 阻擋或劫持。
|
| 475 |
+
# 關閉 ssr_mode 後,伺服器會由 Python 直接處理 7860 端口的所有流量,使 Swagger UI 與 API 順利開通。
|
| 476 |
demo.launch(
|
| 477 |
server_name="0.0.0.0",
|
| 478 |
server_port=7860,
|
| 479 |
+
prevent_thread_lock=False,
|
| 480 |
+
ssr_mode=False
|
| 481 |
)
|
| 482 |
else:
|
| 483 |
import uvicorn
|