FROM python:3.11-slim RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ tesseract-ocr \ libgl1 \ libglib2.0-0 \ curl \ && rm -rf /var/lib/apt/lists/* RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" \ HOME=/home/user \ PYTHONUNBUFFERED=1 WORKDIR /home/user/app COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt COPY --chown=user:user . . # Pre-download the YuNet face-detection ONNX model so the first request # doesn't pay the network round-trip. The yunet module checks this exact # bundled path first, then falls back to runtime download + cache, then # Haar cascades — so a failure here is non-fatal but the build log # should make it OBVIOUS which path the image is on. RUN set -e; \ MODEL_DIR=/home/user/app/app/pipeline/models; \ MODEL_PATH=$MODEL_DIR/face_detection_yunet_2023mar.onnx; \ URL="https://media.githubusercontent.com/media/opencv/opencv_zoo/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx"; \ mkdir -p $MODEL_DIR; \ echo "==> Downloading YuNet model from $URL"; \ if curl -fsSL --retry 3 --retry-delay 2 -o $MODEL_PATH "$URL"; then \ SIZE=$(stat -c%s $MODEL_PATH); \ if [ "$SIZE" -lt 100000 ]; then \ echo "==> WARN: YuNet download too small ($SIZE bytes — likely a Git LFS pointer); removing stub"; \ rm -f $MODEL_PATH; \ echo "==> YuNet will be retried at runtime; Haar fallback otherwise."; \ else \ echo "==> OK: YuNet model bundled at $MODEL_PATH ($SIZE bytes)"; \ fi; \ else \ echo "==> WARN: YuNet pre-download failed (curl exit $?); model will be retried at runtime, Haar fallback otherwise."; \ fi EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]