# HuggingFace Spaces (Docker SDK) — listens on port 7860 (HF default). FROM python:3.11-slim RUN apt-get update && apt-get install -y --no-install-recommends \ libjpeg62-turbo \ libpng16-16 \ libheif1 \ curl ca-certificates \ && rm -rf /var/lib/apt/lists/* RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Standalone `hf` CLI (Xet/buckets) for persistent storage sync. RUN curl -LsSf https://hf.co/cli/install.sh | sh || pip install --no-cache-dir "huggingface_hub[cli]>=0.26" # torch AND torchvision from the SAME CPU index (timm needs torchvision; a # mismatched/absent torchvision causes "operator torchvision::nms does not exist"). RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu COPY --chown=user requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Bake the DINOv2 weights into the image so the first identify is fast (no runtime download). RUN python -c "import timm; timm.create_model('vit_small_patch14_dinov2.lvd142m', pretrained=True)" COPY --chown=user . /app ENV FABRIC_ALGO_DIR=/app EXPOSE 7860 CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]