FROM python:3.12-slim

WORKDIR /app

# Install system dependencies for spaCy compilation
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Download spaCy models at build time to avoid cold-start latency in production.
# fr_core_news_lg (~600MB) is the primary French NER model.
# en_core_web_sm is the English fallback.
RUN python -m spacy download fr_core_news_lg
RUN python -m spacy download en_core_web_sm

# Copy source (after pip install to leverage Docker layer cache)
COPY . .

EXPOSE 8000 50051

CMD ["python", "main.py"]
