Spaces:
Sleeping
Sleeping
| # Dockerfile | |
| # Use a specific Python version slim image for smaller size. | |
| # python:3.10 is recommended as it's well-supported by many ML libraries. | |
| FROM python:3.10-slim | |
| # Set the working directory inside the container | |
| WORKDIR /code | |
| # Set Hugging Face cache directory environment variable. | |
| # Use /tmp which is generally writable in containers and suitable for caching downloads. | |
| # This prevents permission errors when transformers/diffusers try to download models. | |
| ENV HUGGINGFACE_HUB_CACHE="/tmp/huggingface_cache" | |
| # Optional: You could also set HF_HOME for broader config/cache, but HUB_CACHE is specific to downloads. | |
| # ENV HF_HOME="/tmp/hf_home" | |
| # Optional: Explicitly create the directory and ensure permissions, though /tmp usually works. | |
| # RUN mkdir -p $HUGGINGFACE_HUB_CACHE && chmod 777 $HUGGINGFACE_HUB_CACHE | |
| # Install essential system dependencies. | |
| # - ffmpeg: Required by imageio for writing MP4 video files. | |
| # Use --no-install-recommends to keep the image smaller. | |
| # Clean up apt cache afterwards in the SAME layer to reduce image size. | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| && apt-get clean && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Copy just the requirements file first to leverage Docker cache. | |
| # If requirements.txt doesn't change, this layer won't be rebuilt. | |
| COPY requirements.txt requirements.txt | |
| # Install Python dependencies using pip. | |
| # Upgrade pip first. | |
| # Use --no-cache-dir to reduce image size by not storing the pip download cache. | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the application code into the container's working directory | |
| COPY . /code | |
| # Expose the port the application will run on. | |
| # 7860 is the default port expected by Hugging Face Spaces Gradio/Docker SDKs. | |
| EXPOSE 7860 | |
| # Define the command to run the application when the container starts. | |
| # Use uvicorn to run the FastAPI app defined in app.py (the 'app' object). | |
| # --host 0.0.0.0 makes the server accessible from outside the container. | |
| # --port 7860 matches the EXPOSE directive. | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |