Spaces:
Paused
Paused
fix: add permission error handling for HF cache directory initialization
Browse files- app.py +9 -3
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -22,10 +22,16 @@ def _configure_hf_cache() -> None:
|
|
| 22 |
"""
|
| 23 |
preferred_cache_root = Path("/data/cache")
|
| 24 |
fallback_cache_root = Path("/tmp/hf_cache")
|
|
|
|
| 25 |
cache_root = preferred_cache_root if preferred_cache_root.parent.exists() else fallback_cache_root
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
os.environ["HF_HOME"] = str(cache_root)
|
| 31 |
os.environ["TRANSFORMERS_CACHE"] = str(cache_root)
|
|
|
|
| 22 |
"""
|
| 23 |
preferred_cache_root = Path("/data/cache")
|
| 24 |
fallback_cache_root = Path("/tmp/hf_cache")
|
| 25 |
+
|
| 26 |
cache_root = preferred_cache_root if preferred_cache_root.parent.exists() else fallback_cache_root
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
cache_root.mkdir(parents=True, exist_ok=True)
|
| 30 |
+
(cache_root / "hub").mkdir(parents=True, exist_ok=True)
|
| 31 |
+
except PermissionError:
|
| 32 |
+
cache_root = fallback_cache_root
|
| 33 |
+
cache_root.mkdir(parents=True, exist_ok=True)
|
| 34 |
+
(cache_root / "hub").mkdir(parents=True, exist_ok=True)
|
| 35 |
|
| 36 |
os.environ["HF_HOME"] = str(cache_root)
|
| 37 |
os.environ["TRANSFORMERS_CACHE"] = str(cache_root)
|
requirements.txt
CHANGED
|
@@ -24,4 +24,4 @@ Jinja2>=3.1.2
|
|
| 24 |
python-multipart>=0.0.6
|
| 25 |
|
| 26 |
# ββ Local package (editable install) βββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
-
|
|
|
|
| 24 |
python-multipart>=0.0.6
|
| 25 |
|
| 26 |
# ββ Local package (editable install) βββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
+
.
|