| FROM python:3.10-slim | |
| # Create a non-root user (Hugging Face requirement) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| WORKDIR /app | |
| # Switch to root temporarily to install system-level dependencies | |
| USER root | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* | |
| USER user | |
| # Copy requirements and install Python dependencies | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt && \ | |
| python -m spacy download en_core_web_sm | |
| # Copy application code | |
| COPY --chown=user . /app | |
| # Hugging Face Spaces expects port 7860 | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--timeout", "300", "--preload"] | |