# Use a slim Python base image FROM python:3.10-slim # Create a non-root user 'user' with UID 1000 # This is required by Hugging Face Spaces RUN useradd -m -u 1000 user # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV HOME=/home/user ENV PATH=$HOME/.local/bin:$PATH # Install system dependencies required for OpenCV, audio processing, etc. RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ libsndfile1 \ && rm -rf /var/lib/apt/lists/* # Set the working directory WORKDIR $HOME/app # Change ownership of the app directory to the 'user' RUN chown -R user:user $HOME/app # Switch to the non-root user USER user # Copy requirements and install them COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the download script and execute it to cache models # This bakes the downloaded models directly into the Docker image layers COPY --chown=user:user download_models.py . ARG HUGGING_FACE_TOKEN ENV HUGGING_FACE_TOKEN=$HUGGING_FACE_TOKEN RUN python download_models.py # Copy the rest of the application code COPY --chown=user:user app ./app COPY --chown=user:user frontend ./frontend # Expose port (HF Spaces routes traffic to 7860 by default) EXPOSE 7860 # Command to run the application (assuming FastAPI via Uvicorn) CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]