| # ---- Base image ---- | |
| FROM python:3.11-slim | |
| # ---- System setup (add OS libs your deps may need) ---- | |
| # Add or remove packages as needed. Keep it small to speed builds. | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ---- App files ---- | |
| WORKDIR /app | |
| # Copy only requirements first to leverage Docker layer caching | |
| COPY requirements.txt /app/requirements.txt | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Now copy the rest of your code | |
| COPY . /app | |
| # ---- Runtime env ---- | |
| # HF Spaces provides a PORT env var; default to 7860 for local runs | |
| ENV PORT=7860 | |
| ENV PYTHONUNBUFFERED=1 | |
| # Make sure Flask binds publicly; gunicorn will use $PORT | |
| EXPOSE 7860 | |
| # ---- Start command ---- | |
| # Gunicorn will import your Flask app named "app" from run.py | |
| # If your app variable has a different name, change run:app accordingly. | |
| CMD ["gunicorn", "run:app", "--workers", "2", "--threads", "8", "--timeout", "120", "--bind", "0.0.0.0:${PORT}"] | |