Spaces:
Sleeping
Sleeping
| FROM python:3.10-slim | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| ffmpeg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Pré-télécharger le modèle YOLO ET le copier dans /app/models/ | |
| # FIX: sans ça, le modèle est retéléchargé à chaque démarrage | |
| RUN mkdir -p models && \ | |
| python -c "from ultralytics import YOLO; YOLO('yolo11n.pt')" && \ | |
| mv yolo11n.pt models/yolo11n.pt | |
| COPY app.py . | |
| COPY static/ ./static/ | |
| COPY templates/ ./templates/ | |
| RUN mkdir -p uploads outputs logs | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| # FIX: 1 seul worker (le modèle YOLO n'est pas thread-safe entre workers) | |
| # gthread + 4 threads gère la concurrence sans dupliquer le modèle en RAM | |
| CMD ["gunicorn", "-b", "0.0.0.0:7860", \ | |
| "--timeout", "300", \ | |
| "--workers", "1", \ | |
| "--worker-class", "gthread", \ | |
| "--threads", "4", \ | |
| "app:app"] |