FROM python:3.10-slim # Set cache directories to absolute paths to ensure consistency between build and run stages ENV HF_HOME=/root/.cache/huggingface ENV XDG_CACHE_HOME=/root/.cache # Install system dependencies (audio packages, git, compile tools) RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ libsndfile1 \ git \ build-essential \ && rm -rf /var/lib/apt/lists/* # Set the working directory WORKDIR /app # Copy requirements and downloader first to cache models and dependencies COPY requirements.txt . COPY download_models.py . # Create/configure virtual environment using the .venv path RUN python -m venv .venv ENV PATH="/app/.venv/bin:$PATH" # Install Python packages (uses pip cache mount, increases timeout, and uses CPU-only PyTorch to reduce download size) RUN --mount=type=cache,target=/root/.cache/pip \ pip install --default-timeout=100 --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txt # Pre-download and bake all model weights into the image (this runs fully offline afterwards) ARG HF_TOKEN RUN HF_TOKEN=$HF_TOKEN python download_models.py # Copy the rest of the application files (ignoring .venv via .dockerignore) COPY . . # Expose Gradio's default port EXPOSE 7860 # Force Gradio to bind to 0.0.0.0 inside the container ENV GRADIO_SERVER_NAME="0.0.0.0" ENV PYTHONUNBUFFERED=1 # Start the Gradio application CMD ["python", "app.py"]