Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +36 -13
Dockerfile
CHANGED
|
@@ -1,28 +1,51 @@
|
|
| 1 |
-
# Dockerfile
|
| 2 |
|
| 3 |
-
# Use a specific Python version slim image for smaller size
|
| 4 |
-
#
|
| 5 |
FROM python:3.10-slim
|
| 6 |
|
|
|
|
| 7 |
WORKDIR /code
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
COPY requirements.txt requirements.txt
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 18 |
pip install --no-cache-dir -r requirements.txt
|
| 19 |
|
|
|
|
| 20 |
COPY . /code
|
| 21 |
|
| 22 |
-
# Expose the port
|
|
|
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
# Use
|
| 27 |
-
#
|
|
|
|
| 28 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Dockerfile
|
| 2 |
|
| 3 |
+
# Use a specific Python version slim image for smaller size.
|
| 4 |
+
# python:3.10 is recommended as it's well-supported by many ML libraries.
|
| 5 |
FROM python:3.10-slim
|
| 6 |
|
| 7 |
+
# Set the working directory inside the container
|
| 8 |
WORKDIR /code
|
| 9 |
|
| 10 |
+
# Set Hugging Face cache directory environment variable.
|
| 11 |
+
# Use /tmp which is generally writable in containers and suitable for caching downloads.
|
| 12 |
+
# This prevents permission errors when transformers/diffusers try to download models.
|
| 13 |
+
ENV HUGGINGFACE_HUB_CACHE="/tmp/huggingface_cache"
|
| 14 |
+
# Optional: You could also set HF_HOME for broader config/cache, but HUB_CACHE is specific to downloads.
|
| 15 |
+
# ENV HF_HOME="/tmp/hf_home"
|
| 16 |
|
| 17 |
+
# Optional: Explicitly create the directory and ensure permissions, though /tmp usually works.
|
| 18 |
+
# RUN mkdir -p $HUGGINGFACE_HUB_CACHE && chmod 777 $HUGGINGFACE_HUB_CACHE
|
| 19 |
+
|
| 20 |
+
# Install essential system dependencies.
|
| 21 |
+
# - ffmpeg: Required by imageio for writing MP4 video files.
|
| 22 |
+
# Use --no-install-recommends to keep the image smaller.
|
| 23 |
+
# Clean up apt cache afterwards in the SAME layer to reduce image size.
|
| 24 |
+
RUN apt-get update && \
|
| 25 |
+
apt-get install -y --no-install-recommends \
|
| 26 |
+
ffmpeg \
|
| 27 |
+
&& apt-get clean && \
|
| 28 |
+
rm -rf /var/lib/apt/lists/*
|
| 29 |
+
|
| 30 |
+
# Copy just the requirements file first to leverage Docker cache.
|
| 31 |
+
# If requirements.txt doesn't change, this layer won't be rebuilt.
|
| 32 |
COPY requirements.txt requirements.txt
|
| 33 |
+
|
| 34 |
+
# Install Python dependencies using pip.
|
| 35 |
+
# Upgrade pip first.
|
| 36 |
+
# Use --no-cache-dir to reduce image size by not storing the pip download cache.
|
| 37 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 38 |
pip install --no-cache-dir -r requirements.txt
|
| 39 |
|
| 40 |
+
# Copy the rest of the application code into the container's working directory
|
| 41 |
COPY . /code
|
| 42 |
|
| 43 |
+
# Expose the port the application will run on.
|
| 44 |
+
# 7860 is the default port expected by Hugging Face Spaces Gradio/Docker SDKs.
|
| 45 |
EXPOSE 7860
|
| 46 |
|
| 47 |
+
# Define the command to run the application when the container starts.
|
| 48 |
+
# Use uvicorn to run the FastAPI app defined in app.py (the 'app' object).
|
| 49 |
+
# --host 0.0.0.0 makes the server accessible from outside the container.
|
| 50 |
+
# --port 7860 matches the EXPOSE directive.
|
| 51 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|