Spaces:
Running
Running
File size: 1,916 Bytes
2128d4b 2619c42 2128d4b 2619c42 8c7cc2e 2619c42 2128d4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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"]
|