Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +26 -27
Dockerfile
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
ENV PYTHONDONTWRITEBYTECODE
|
| 5 |
-
ENV PYTHONUNBUFFERED
|
| 6 |
ENV STREAMLIT_SERVER_HEADLESS=true
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
ENV HF_HOME=/app/hf_cache
|
| 10 |
-
ENV TRANSFORMERS_CACHE=/app/hf_cache
|
| 11 |
-
ENV STREAMLIT_CACHE_DIR=/app/.streamlit_cache
|
| 12 |
-
ENV MPLCONFIGDIR=/app/matplotlib
|
| 13 |
-
|
| 14 |
-
# System dependencies (needed for OpenCV, etc.)
|
| 15 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
-
libgl1
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
COPY requirements.txt .
|
| 24 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# Create cache dirs so we don’t get permission denied at runtime
|
| 30 |
-
RUN mkdir -p /app/hf_cache /app/.streamlit_cache /app/matplotlib /app/logs
|
| 31 |
-
|
| 32 |
-
# Hugging Face expects port 7860
|
| 33 |
-
EXPOSE 7860
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. Base Image
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# 2. Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
| 6 |
+
ENV PYTHONUNBUFFERED 1
|
| 7 |
ENV STREAMLIT_SERVER_HEADLESS=true
|
| 8 |
+
# --- THE DEFINITIVE FIX IS HERE ---
|
| 9 |
+
# Tell Hugging Face to use a cache directory INSIDE the user's home folder
|
| 10 |
+
ENV HF_HOME=/home/user/.cache/huggingface
|
| 11 |
+
# --- END FIX ---
|
| 12 |
|
| 13 |
+
# 3. Install System Dependencies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
git git-lfs libgl1 \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# 4. Create and switch to a non-root user
|
| 19 |
+
RUN useradd -m -u 1000 user
|
| 20 |
+
USER user
|
| 21 |
+
WORKDIR /home/user/app
|
| 22 |
|
| 23 |
+
# 5. Copy and install Python requirements
|
| 24 |
+
COPY --chown=user:user requirements.txt packages.txt ./
|
| 25 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 26 |
|
| 27 |
+
# 6. Pre-download the model's configuration files (as the correct user)
|
| 28 |
+
# This is a small download and ensures the cache directory is created.
|
| 29 |
+
RUN python -c "from transformers import AutoImageProcessor; AutoImageProcessor.from_pretrained('google/efficientnet-b2')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# 7. Copy application code and model artifacts
|
| 32 |
+
COPY --chown=user:user . .
|
| 33 |
+
RUN git lfs pull
|
| 34 |
|
| 35 |
+
# 8. Expose port and run the app
|
| 36 |
+
EXPOSE 8501
|
| 37 |
+
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 38 |
+
ENTRYPOINT ["python", "-m", "streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|