# Use the official lightweight Python image FROM python:3.10-slim # Set the working directory in the container WORKDIR /app # Copy requirements first COPY requirements.txt . # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY . . # Create a non-root user (Security Best Practice for HF Spaces) RUN useradd -m -u 1000 user USER user # HF Spaces Port ENV PORT=7860 EXPOSE 7860 # FIXED CMD: Use 'gthread' worker to handle async I/O within Flask CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--threads", "4", "--worker-class", "gthread", "--timeout", "120", "app:app"]