Spaces:
Sleeping
Sleeping
p2002814
commited on
Commit
·
617c3bf
1
Parent(s):
9091f2c
Fix: use /app/cache for Hugging Face models to avoid permission errors in Docker
Browse files- Dockerfile +1 -4
- utils/mlp.py +4 -3
Dockerfile
CHANGED
|
@@ -10,10 +10,6 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
git \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
# Set Hugging Face cache to writable directory
|
| 14 |
-
ENV TRANSFORMERS_CACHE=/app/cache
|
| 15 |
-
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
| 16 |
-
|
| 17 |
# Copy requirements
|
| 18 |
COPY requirements.txt .
|
| 19 |
|
|
@@ -27,6 +23,7 @@ COPY . .
|
|
| 27 |
# Expose Uvicorn port
|
| 28 |
EXPOSE 7860
|
| 29 |
|
|
|
|
| 30 |
USER root
|
| 31 |
|
| 32 |
# Start command
|
|
|
|
| 10 |
git \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Copy requirements
|
| 14 |
COPY requirements.txt .
|
| 15 |
|
|
|
|
| 23 |
# Expose Uvicorn port
|
| 24 |
EXPOSE 7860
|
| 25 |
|
| 26 |
+
# Run as root (optionnel, pas strictement nécessaire)
|
| 27 |
USER root
|
| 28 |
|
| 29 |
# Start command
|
utils/mlp.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
-
|
| 4 |
-
os.
|
|
|
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import joblib
|
|
@@ -38,5 +39,5 @@ def load_model_and_metadata(model_path: str, model_type: str = "pytorch"):
|
|
| 38 |
best_threshold = checkpoint.get('best_threshold', 0.5)
|
| 39 |
label_encoder = checkpoint['label_encoder']
|
| 40 |
|
| 41 |
-
embedding_model = SentenceTransformer('all-mpnet-base-v2', cache_folder=
|
| 42 |
return model, embedding_model, best_threshold, label_encoder
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
cache_dir = os.path.expanduser("~/.cache/huggingface")
|
| 4 |
+
os.environ["TRANSFORMERS_CACHE"] = cache_dir
|
| 5 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 6 |
|
| 7 |
import torch
|
| 8 |
import joblib
|
|
|
|
| 39 |
best_threshold = checkpoint.get('best_threshold', 0.5)
|
| 40 |
label_encoder = checkpoint['label_encoder']
|
| 41 |
|
| 42 |
+
embedding_model = SentenceTransformer('all-mpnet-base-v2', cache_folder=cache_dir)
|
| 43 |
return model, embedding_model, best_threshold, label_encoder
|