Spaces:
Sleeping
Sleeping
| # Dockerfile — Enterprise Lens V3 | |
| # InsightFace models download on first run (not at build time) | |
| # This avoids build timeout and network issues during Docker build | |
| FROM python:3.10-slim | |
| WORKDIR /app | |
| # ── System deps ────────────────────────────────────────────────── | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 libglib2.0-0 libgomp1 git \ | |
| build-essential cmake g++ \ | |
| wget ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ── Step 1: Build tools (MUST be before insightface) ───────────── | |
| RUN pip install --no-cache-dir \ | |
| "numpy<2.0" \ | |
| "setuptools>=65" \ | |
| wheel \ | |
| cython \ | |
| scikit-build \ | |
| cmake | |
| # ── Step 2: onnxruntime (MUST be before insightface) ───────────── | |
| RUN pip install --no-cache-dir onnxruntime | |
| # ── Step 3: insightface ─────────────────────────────────────────── | |
| RUN pip install --no-cache-dir --prefer-binary "insightface>=0.7.3" | |
| # ── Step 4: Remaining requirements ─────────────────────────────── | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --prefer-binary -r requirements.txt | |
| # ── Copy app code ───────────────────────────────────────────────── | |
| COPY . . | |
| RUN mkdir -p temp_uploads saved_images && chmod -R 777 temp_uploads saved_images | |
| # ── Hugging Face Auth Token ────────────────────────────────────── | |
| # Define the argument so Docker accepts it during build | |
| ARG HF_TOKEN | |
| # Set it as an environment variable so Python/HuggingFace can see it | |
| ENV HF_TOKEN=$HF_TOKEN | |
| # ── Pre-download ONLY transformers + YOLO at build time ────────── | |
| # InsightFace models download on first startup (cached after that) | |
| RUN python - <<'EOF' | |
| import os | |
| os.environ["TRANSFORMERS_VERBOSITY"] = "error" | |
| print("Pre-downloading SigLIP...") | |
| from transformers import AutoProcessor, AutoModel | |
| AutoProcessor.from_pretrained("google/siglip-base-patch16-224", use_fast=True) | |
| AutoModel.from_pretrained("google/siglip-base-patch16-224") | |
| print("SigLIP done") | |
| print("Pre-downloading DINOv2...") | |
| from transformers import AutoImageProcessor | |
| AutoImageProcessor.from_pretrained("facebook/dinov2-base") | |
| AutoModel.from_pretrained("facebook/dinov2-base") | |
| print("DINOv2 done") | |
| print("Pre-downloading YOLO seg...") | |
| from ultralytics import YOLO | |
| YOLO("yolo11n-seg.pt") | |
| print("YOLO done") | |
| print("Build complete! InsightFace models download on first startup.") | |
| EOF | |
| EXPOSE 7860 | |
| # 2 workers when running as Gateway (I/O-bound HTTP calls to remote Spaces). | |
| # Keep at 1 for monolith mode (CPU-bound AI inference — extra workers add overhead). | |
| ENV WEB_CONCURRENCY=2 | |
| CMD uvicorn main:app \ | |
| --host 0.0.0.0 \ | |
| --port 7860 \ |