Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +12 -8
Dockerfile
CHANGED
|
@@ -23,28 +23,32 @@ RUN pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch
|
|
| 23 |
# Install the remaining Python dependencies.
|
| 24 |
RUN pip install --no-cache-dir -r /app/requirements.txt
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# ---- Pre-download the model at build time ----
|
| 27 |
# This bakes the model weights into the image so the container starts
|
| 28 |
# fast and does not need network access to Hugging Face at runtime.
|
| 29 |
ARG IMAGE_MODEL=stabilityai/sd-turbo
|
| 30 |
ENV IMAGE_MODEL=${IMAGE_MODEL}
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# ---- Copy application code ----
|
| 34 |
COPY server.py /app/server.py
|
|
|
|
| 35 |
|
| 36 |
# ---- Environment defaults ----
|
| 37 |
ENV MODEL_LOCAL_DIR=/app/models/sd-turbo
|
| 38 |
ENV DEFAULT_STEPS=2
|
| 39 |
ENV DEFAULT_GUIDANCE=0
|
| 40 |
ENV PYTHONUNBUFFERED=1
|
| 41 |
-
ENV HF_HOME=/app/.cache/huggingface
|
| 42 |
-
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
|
| 43 |
-
|
| 44 |
-
# ---- HF Spaces requires a non-root user with UID 1000 ----
|
| 45 |
-
RUN useradd -m -u 1000 appuser && \
|
| 46 |
-
mkdir -p /app/.cache/huggingface && \
|
| 47 |
-
chown -R appuser:appuser /app
|
| 48 |
|
| 49 |
USER 1000
|
| 50 |
|
|
|
|
| 23 |
# Install the remaining Python dependencies.
|
| 24 |
RUN pip install --no-cache-dir -r /app/requirements.txt
|
| 25 |
|
| 26 |
+
# ---- Create the non-root user required by HF Spaces before downloading ----
|
| 27 |
+
# so the downloaded model is owned by the right user from the start
|
| 28 |
+
# (avoids a slow recursive chown of multi-GB model weights later).
|
| 29 |
+
# "|| true" guards against a base-image UID/GID 1000 already existing.
|
| 30 |
+
RUN (useradd -m -u 1000 appuser || true) && \
|
| 31 |
+
mkdir -p /app/models /app/.cache/huggingface && \
|
| 32 |
+
chown -R 1000:1000 /app
|
| 33 |
+
|
| 34 |
# ---- Pre-download the model at build time ----
|
| 35 |
# This bakes the model weights into the image so the container starts
|
| 36 |
# fast and does not need network access to Hugging Face at runtime.
|
| 37 |
ARG IMAGE_MODEL=stabilityai/sd-turbo
|
| 38 |
ENV IMAGE_MODEL=${IMAGE_MODEL}
|
| 39 |
+
ENV HF_HOME=/app/.cache/huggingface
|
| 40 |
+
ENV HF_HUB_ENABLE_HF_TRANSFER=0
|
| 41 |
+
RUN python -m huggingface_hub.commands.huggingface_cli download ${IMAGE_MODEL} --local-dir /app/models/sd-turbo
|
| 42 |
|
| 43 |
# ---- Copy application code ----
|
| 44 |
COPY server.py /app/server.py
|
| 45 |
+
RUN chown 1000:1000 /app/server.py
|
| 46 |
|
| 47 |
# ---- Environment defaults ----
|
| 48 |
ENV MODEL_LOCAL_DIR=/app/models/sd-turbo
|
| 49 |
ENV DEFAULT_STEPS=2
|
| 50 |
ENV DEFAULT_GUIDANCE=0
|
| 51 |
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
USER 1000
|
| 54 |
|