| # Use an official Python runtime as a parent image | |
| FROM python:3.9-slim | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # Install system dependencies: | |
| # - build-essential: For compiling some Python packages if needed | |
| # - curl, git, software-properties-common: General utilities, git for some pip installs | |
| # - ffmpeg: For video processing | |
| # - python3-dev: For C extensions if any Python package needs to build them | |
| # - libsndfile1: For soundfile to work correctly | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| git \ | |
| software-properties-common \ | |
| ffmpeg \ | |
| python3-dev \ | |
| libsndfile1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy the requirements file into the container at /app | |
| COPY requirements.txt ./ | |
| # Install any needed packages specified in requirements.txt | |
| # --no-cache-dir: Reduces image size by not storing the pip cache | |
| # It's good practice to upgrade pip first | |
| RUN pip install --no-cache-dir --upgrade pip | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the application code into the container at /app | |
| COPY . . | |
| # Make port 7860 available to the world outside this container (Streamlit default) | |
| # Hugging Face Spaces will handle the actual port mapping. | |
| EXPOSE 7860 | |
| # Define environment variables for Hugging Face Hub caching (optional but good practice) | |
| # These will be overridden by HF Spaces secrets/vars if set there, but good defaults. | |
| ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface/hub | |
| ENV HF_HOME=/app/.cache/huggingface | |
| ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub | |
| ENV DIFFUSERS_CACHE=/app/.cache/huggingface/hub | |
| # Create the cache directory and set permissions (if needed, usually pip creates it) | |
| # RUN mkdir -p /app/.cache/huggingface/hub && chmod -R 777 /app/.cache | |
| # Command to run the Streamlit application | |
| # The --server.port and --server.address are important for HF Spaces. | |
| # --server.fileWatcherType none can prevent issues in some environments. | |
| CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.fileWatcherType=none"] |