# ============================================================================= # Dockerfile — CIM-10 ML Backend v2 (FastAPI + DrBERT NER) # ============================================================================= # HF Spaces : CPU free tier, port 7860 FROM python:3.10-slim # User non-root (requis par HF Spaces) RUN useradd -m -u 1000 user WORKDIR /app # Dépendances système RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Dépendances Python COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pré-télécharger le modèle NER dans l'image Docker # (évite un téléchargement de ~440 Mo au premier démarrage) RUN python -c "from transformers import pipeline; pipeline('token-classification', model='medkit/DrBERT-CASM2', aggregation_strategy='simple', device=-1)" # Code applicatif COPY app.py . COPY cim10_index.json . # Permissions RUN chown -R user:user /app USER user # Le cache transformers doit être accessible par l'utilisateur non-root ENV HF_HOME=/app/.cache/huggingface RUN mkdir -p /app/.cache/huggingface EXPOSE 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "120"]