Commit
·
77685c6
1
Parent(s):
d54232c
fix: Use app directory for cache to resolve HuggingFace Spaces permissions
Browse files- Change cache directory from ~/.cache to app/.cache for write permissions
- Fix PermissionError: [Errno 13] Permission denied: '/.cache'
- Use os.getcwd() based paths for HuggingFace Spaces compatibility
- Ensure all directories are writable within the container
- highlights_api.py +7 -6
- src/smolvlm2_handler.py +5 -4
highlights_api.py
CHANGED
|
@@ -7,14 +7,15 @@ Converts your SmolVLM2 + Whisper system into a web API for Android apps
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
|
| 10 |
-
# Set cache directories to
|
| 11 |
-
CACHE_DIR = os.path.
|
| 12 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
|
|
|
| 13 |
os.environ['HF_HOME'] = CACHE_DIR
|
| 14 |
os.environ['TRANSFORMERS_CACHE'] = CACHE_DIR
|
| 15 |
os.environ['HF_DATASETS_CACHE'] = CACHE_DIR
|
| 16 |
-
os.environ['TORCH_HOME'] = os.path.
|
| 17 |
-
os.environ['XDG_CACHE_HOME'] = os.path.
|
| 18 |
os.environ['HUGGINGFACE_HUB_CACHE'] = CACHE_DIR
|
| 19 |
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
| 20 |
|
|
@@ -88,8 +89,8 @@ completed_jobs = {}
|
|
| 88 |
import tempfile
|
| 89 |
import stat
|
| 90 |
|
| 91 |
-
# Use
|
| 92 |
-
TEMP_DIR =
|
| 93 |
OUTPUTS_DIR = os.path.join(os.getcwd(), "outputs")
|
| 94 |
|
| 95 |
# Create directories with proper permissions
|
|
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
|
| 10 |
+
# Set cache directories to writable locations for HuggingFace Spaces
|
| 11 |
+
CACHE_DIR = os.path.join(os.getcwd(), ".cache", "huggingface")
|
| 12 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
| 13 |
+
os.makedirs(os.path.join(os.getcwd(), ".cache", "torch"), exist_ok=True)
|
| 14 |
os.environ['HF_HOME'] = CACHE_DIR
|
| 15 |
os.environ['TRANSFORMERS_CACHE'] = CACHE_DIR
|
| 16 |
os.environ['HF_DATASETS_CACHE'] = CACHE_DIR
|
| 17 |
+
os.environ['TORCH_HOME'] = os.path.join(os.getcwd(), ".cache", "torch")
|
| 18 |
+
os.environ['XDG_CACHE_HOME'] = os.path.join(os.getcwd(), ".cache")
|
| 19 |
os.environ['HUGGINGFACE_HUB_CACHE'] = CACHE_DIR
|
| 20 |
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
| 21 |
|
|
|
|
| 89 |
import tempfile
|
| 90 |
import stat
|
| 91 |
|
| 92 |
+
# Use app directory for HuggingFace Spaces compatibility
|
| 93 |
+
TEMP_DIR = os.path.join(os.getcwd(), "temp")
|
| 94 |
OUTPUTS_DIR = os.path.join(os.getcwd(), "outputs")
|
| 95 |
|
| 96 |
# Create directories with proper permissions
|
src/smolvlm2_handler.py
CHANGED
|
@@ -7,15 +7,16 @@ Handles loading and inference with SmolVLM2-256M-Instruct model (smallest model
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
|
| 10 |
-
# Set cache directories to
|
| 11 |
if 'HF_HOME' not in os.environ:
|
| 12 |
-
CACHE_DIR = os.path.
|
| 13 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
|
|
|
| 14 |
os.environ['HF_HOME'] = CACHE_DIR
|
| 15 |
os.environ['TRANSFORMERS_CACHE'] = CACHE_DIR
|
| 16 |
os.environ['HF_DATASETS_CACHE'] = CACHE_DIR
|
| 17 |
-
os.environ['TORCH_HOME'] = os.path.
|
| 18 |
-
os.environ['XDG_CACHE_HOME'] = os.path.
|
| 19 |
os.environ['HUGGINGFACE_HUB_CACHE'] = CACHE_DIR
|
| 20 |
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
| 21 |
|
|
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
|
| 10 |
+
# Set cache directories to writable locations for HuggingFace Spaces
|
| 11 |
if 'HF_HOME' not in os.environ:
|
| 12 |
+
CACHE_DIR = os.path.join(os.getcwd(), ".cache", "huggingface")
|
| 13 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
| 14 |
+
os.makedirs(os.path.join(os.getcwd(), ".cache", "torch"), exist_ok=True)
|
| 15 |
os.environ['HF_HOME'] = CACHE_DIR
|
| 16 |
os.environ['TRANSFORMERS_CACHE'] = CACHE_DIR
|
| 17 |
os.environ['HF_DATASETS_CACHE'] = CACHE_DIR
|
| 18 |
+
os.environ['TORCH_HOME'] = os.path.join(os.getcwd(), ".cache", "torch")
|
| 19 |
+
os.environ['XDG_CACHE_HOME'] = os.path.join(os.getcwd(), ".cache")
|
| 20 |
os.environ['HUGGINGFACE_HUB_CACHE'] = CACHE_DIR
|
| 21 |
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
| 22 |
|