Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,34 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
|
| 4 |
def download_model():
|
| 5 |
-
|
| 6 |
-
model_dir = "/app/checkpoint"
|
| 7 |
-
model_path = os.path.join(model_dir, "final_model_K_30.pth")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
if not os.path.exists(model_path):
|
| 14 |
-
print("
|
| 15 |
try:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
return True
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
-
print(f"
|
| 28 |
return False
|
| 29 |
else:
|
| 30 |
print("模型文件已存在")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
def download_model():
|
| 5 |
+
model_path = "checkpoint/final_model_K_30.pth"
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# 检查并修复目录权限问题
|
| 8 |
+
try:
|
| 9 |
+
os.makedirs("checkpoint", exist_ok=True)
|
| 10 |
+
except PermissionError:
|
| 11 |
+
print("无法创建目录,尝试使用当前目录")
|
| 12 |
+
model_path = "final_model_K_30.pth" # 直接下载到当前目录
|
| 13 |
|
| 14 |
if not os.path.exists(model_path):
|
| 15 |
+
print("下载模型文件...")
|
| 16 |
try:
|
| 17 |
+
url = "https://huggingface.co/spaces/Hanxiaofeng123/Deepcube/resolve/main/checkpoint/final_model_K_30.pth"
|
| 18 |
+
|
| 19 |
+
response = requests.get(url, stream=True, timeout=60)
|
| 20 |
+
response.raise_for_status()
|
| 21 |
+
|
| 22 |
+
# 直接下载到文件
|
| 23 |
+
with open(model_path, 'wb') as f:
|
| 24 |
+
for data in response.iter_content(8192):
|
| 25 |
+
f.write(data)
|
| 26 |
+
|
| 27 |
+
print(f"下载完成: {model_path}")
|
| 28 |
return True
|
| 29 |
|
| 30 |
except Exception as e:
|
| 31 |
+
print(f"下载失败: {e}")
|
| 32 |
return False
|
| 33 |
else:
|
| 34 |
print("模型文件已存在")
|