FROM python:3.11-slim RUN apt-get update && apt-get install -y \ ffmpeg \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY requirements.txt . # Install torch CPU-only first (~250MB vs ~2GB for the default CUDA build) RUN \ pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu RUN \ pip install --timeout 300 -r requirements.txt COPY app/ ./app/ COPY scripts/ ./scripts/ EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 # Models download on first cold start and are cached by HF Spaces persistently. # preload_models.py runs before uvicorn so the API is ready when /health passes. CMD ["sh", "-c", "python scripts/preload_models.py && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 1"]