# Lightweight Python base image FROM python:3.12-slim # Hugging Face Docker spaces run the container as a non-root user with UID 1000 RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /home/user/app # Install dependencies first so Docker can cache this layer COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt # Copy the API code and the serialized model COPY --chown=user . . # Serve the Flask app with gunicorn on port 7860 (the port Hugging Face exposes) EXPOSE 7860 CMD ["gunicorn", "--workers", "2", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"]