Spaces:
Sleeping
Sleeping
Commit
·
12da50b
1
Parent(s):
294d497
Fix HF cache: use /tmp writable cache and fallback env
Browse files- Dockerfile +8 -4
- src/app.py +6 -0
Dockerfile
CHANGED
@@ -13,9 +13,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
13 |
&& rm -rf /var/lib/apt/lists/*
|
14 |
|
15 |
# set cache dir to a writable location
|
16 |
-
ENV TRANSFORMERS_CACHE=/
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Copy the dependency file first to leverage Docker's layer caching
|
21 |
COPY requirements.txt .
|
@@ -31,5 +36,4 @@ COPY src/ src/
|
|
31 |
EXPOSE 7860
|
32 |
|
33 |
# Define the default command to run the application.
|
34 |
-
# The server_name="0.0.0.0" is crucial for it to be accessible inside Docker.
|
35 |
CMD ["python", "-m", "src.app"]
|
|
|
13 |
&& rm -rf /var/lib/apt/lists/*
|
14 |
|
15 |
# set cache dir to a writable location
|
16 |
+
ENV TRANSFORMERS_CACHE=/tmp/hf_cache \
|
17 |
+
HF_HOME=/tmp/hf_home \
|
18 |
+
HF_HUB_CACHE=/tmp/hf_hub_cache \
|
19 |
+
XDG_CACHE_HOME=/tmp
|
20 |
+
|
21 |
+
# Create necessary directories for Hugging Face cache and set permissions
|
22 |
+
RUN mkdir -p /tmp/hf_cache /tmp/hf_home /tmp/hf_hub_cache \
|
23 |
+
&& chmod -R 777 /tmp/hf_cache /tmp/hf_home /tmp/hf_hub_cache
|
24 |
|
25 |
# Copy the dependency file first to leverage Docker's layer caching
|
26 |
COPY requirements.txt .
|
|
|
36 |
EXPOSE 7860
|
37 |
|
38 |
# Define the default command to run the application.
|
|
|
39 |
CMD ["python", "-m", "src.app"]
|
src/app.py
CHANGED
@@ -5,6 +5,12 @@ from src.utils.exceptions import AppError
|
|
5 |
from src.logging_config import logger
|
6 |
from src import config
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def create_controller():
|
10 |
"""Factory function to create a new controller instance."""
|
|
|
5 |
from src.logging_config import logger
|
6 |
from src import config
|
7 |
|
8 |
+
# Set environment variables for Hugging Face cache directories
|
9 |
+
os.environ.setdefault("TRANSFORMERS_CACHE", "/tmp/hf_cache")
|
10 |
+
os.environ.setdefault("HF_HOME", "/tmp/hf_home")
|
11 |
+
os.environ.setdefault("HF_HUB_CACHE", "/tmp/hf_hub_cache")
|
12 |
+
os.environ.setdefault("XDG_CACHE_HOME", "/tmp")
|
13 |
+
|
14 |
|
15 |
def create_controller():
|
16 |
"""Factory function to create a new controller instance."""
|