Spaces:
Sleeping
Sleeping
Commit ·
291da20
1
Parent(s): 73ae8e9
Add Hugging Face config files to subfolder
Browse files
app.py
CHANGED
|
@@ -15,14 +15,17 @@ from pydantic import BaseModel, Field
|
|
| 15 |
# ==========================================
|
| 16 |
# ZeroGPU 啟動相容性設定 (針對 Hugging Face 免費版限制)
|
| 17 |
# ==========================================
|
|
|
|
| 18 |
try:
|
| 19 |
import spaces
|
| 20 |
except ImportError:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@spaces.GPU
|
| 28 |
def dummy_gpu_function():
|
|
|
|
| 15 |
# ==========================================
|
| 16 |
# ZeroGPU 啟動相容性設定 (針對 Hugging Face 免費版限制)
|
| 17 |
# ==========================================
|
| 18 |
+
# 1. 為了相容本地開發環境,若無 spaces 套件則動態註冊 Mock 模組至 sys.modules
|
| 19 |
try:
|
| 20 |
import spaces
|
| 21 |
except ImportError:
|
| 22 |
+
import types
|
| 23 |
+
fake_spaces = types.ModuleType("spaces")
|
| 24 |
+
fake_spaces.GPU = lambda func: func
|
| 25 |
+
sys.modules["spaces"] = fake_spaces
|
| 26 |
+
|
| 27 |
+
# 2. 必須在最外層進行頂級導入 (Top-level Import),以通過 Hugging Face 的 AST 靜態語法掃描
|
| 28 |
+
import spaces
|
| 29 |
|
| 30 |
@spaces.GPU
|
| 31 |
def dummy_gpu_function():
|