FROM python:3.11-slim WORKDIR /app # Install dependencies first (layer caching) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # HuggingFace Spaces runs as a non-root user RUN useradd -m appuser && chown -R appuser /app USER appuser EXPOSE 7860 CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--threads", "4", "--worker-class", "gthread", "--timeout", "180", "app:app"]