Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,25 @@ from pydantic import BaseModel
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import os
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# 正确加载模型(从缓存或下载)
|
| 7 |
classifier = pipeline(
|
| 8 |
"text-classification",
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# 验证缓存目录可写
|
| 11 |
+
cache_dir = Path(os.getenv("HF_HOME", ""))
|
| 12 |
+
if not cache_dir.exists():
|
| 13 |
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
test_file = cache_dir / "permission_test.txt"
|
| 16 |
+
try:
|
| 17 |
+
with open(test_file, "w") as f:
|
| 18 |
+
f.write("test")
|
| 19 |
+
os.remove(test_file)
|
| 20 |
+
print("✅ Cache directory is writable")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"❌ Cache directory write failed: {str(e)}")
|
| 23 |
+
raise
|
| 24 |
+
|
| 25 |
# 正确加载模型(从缓存或下载)
|
| 26 |
classifier = pipeline(
|
| 27 |
"text-classification",
|