Spaces:
Sleeping
Sleeping
fix: build issues
Browse files- Dockerfile +12 -21
- requirements.txt +4 -0
Dockerfile
CHANGED
|
@@ -1,18 +1,17 @@
|
|
| 1 |
# Dockerfile — Enterprise Lens V4
|
| 2 |
-
#
|
| 3 |
-
# Changes vs V3:
|
| 4 |
-
# • Removed deepface / GhostFaceNet / RetinaFace entirely
|
| 5 |
-
# • Added insightface + onnxruntime (SCRFD + ArcFace-R100)
|
| 6 |
-
# • AdaFace IR-50 MS1MV2 pre-downloaded at build time (needs HF_TOKEN)
|
| 7 |
-
# • Single worker — InsightFace ONNX is NOT thread-safe
|
| 8 |
-
# • Index dims: enterprise-faces=1024, enterprise-objects=1536
|
| 9 |
|
| 10 |
FROM python:3.10-slim
|
| 11 |
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
# ── System deps ───────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
|
|
| 16 |
libgl1 \
|
| 17 |
libglib2.0-0 \
|
| 18 |
libgomp1 \
|
|
@@ -21,9 +20,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 21 |
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
|
| 23 |
# ── HF_TOKEN build arg ────────────────────────────────────────────
|
| 24 |
-
#
|
| 25 |
-
# HF Spaces passes Repository Secrets as
|
| 26 |
-
# AND Docker build ARGs with the same name automatically.
|
| 27 |
ARG HF_TOKEN=""
|
| 28 |
ENV HF_TOKEN=${HF_TOKEN}
|
| 29 |
|
|
@@ -37,7 +35,6 @@ COPY . .
|
|
| 37 |
RUN mkdir -p temp_uploads saved_images && chmod -R 777 temp_uploads saved_images
|
| 38 |
|
| 39 |
# ── Pre-download public models at BUILD time ──────────────────────
|
| 40 |
-
# SigLIP, DINOv2, YOLO, InsightFace buffalo_l — no token needed
|
| 41 |
RUN python - <<'EOF'
|
| 42 |
import os, sys
|
| 43 |
|
|
@@ -68,10 +65,7 @@ print("InsightFace buffalo_l done")
|
|
| 68 |
print("All public models pre-downloaded successfully")
|
| 69 |
EOF
|
| 70 |
|
| 71 |
-
# ── Pre-download AdaFace (
|
| 72 |
-
# Split from above so a failure here does NOT fail the whole build.
|
| 73 |
-
# If HF_TOKEN is missing or wrong, build still succeeds and the app
|
| 74 |
-
# runs in ArcFace-only fallback mode (zero-padded to 1024-D).
|
| 75 |
RUN python - <<'EOF'
|
| 76 |
import os, sys, traceback
|
| 77 |
|
|
@@ -81,8 +75,7 @@ CACHE_PATH = os.path.expanduser("~/.cvlface_cache/minchul/cvlface_adaface_ir50_m
|
|
| 81 |
|
| 82 |
if not HF_TOKEN:
|
| 83 |
print("HF_TOKEN not set - skipping AdaFace pre-download")
|
| 84 |
-
print("
|
| 85 |
-
print("Fallback: ArcFace-only zero-padded to 1024-D (build succeeds)")
|
| 86 |
sys.exit(0)
|
| 87 |
|
| 88 |
try:
|
|
@@ -120,19 +113,17 @@ try:
|
|
| 120 |
with torch.no_grad():
|
| 121 |
out = model(torch.zeros(1, 3, 112, 112))
|
| 122 |
emb = out if isinstance(out, torch.Tensor) else out.embedding
|
| 123 |
-
print("AdaFace
|
| 124 |
-
print("1024-D FULL FUSION will be active at runtime")
|
| 125 |
|
| 126 |
except Exception as e:
|
| 127 |
print("AdaFace pre-download failed: " + str(e))
|
| 128 |
print(traceback.format_exc()[-400:])
|
| 129 |
-
print("Build continues -
|
| 130 |
sys.exit(0)
|
| 131 |
EOF
|
| 132 |
|
| 133 |
EXPOSE 7860
|
| 134 |
|
| 135 |
-
# ── Single worker — InsightFace ONNX is NOT thread-safe ──────────
|
| 136 |
ENV WEB_CONCURRENCY=1
|
| 137 |
|
| 138 |
CMD uvicorn main:app \
|
|
|
|
| 1 |
# Dockerfile — Enterprise Lens V4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
FROM python:3.10-slim
|
| 4 |
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
# ── System deps ───────────────────────────────────────────────────
|
| 8 |
+
# g++ / build-essential : required to compile insightface C++ extensions
|
| 9 |
+
# libgl1 + libglib2.0-0 : OpenCV headless
|
| 10 |
+
# libgomp1 : OpenMP for ONNX runtime
|
| 11 |
+
# git + curl : HF hub downloads
|
| 12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
+
build-essential \
|
| 14 |
+
g++ \
|
| 15 |
libgl1 \
|
| 16 |
libglib2.0-0 \
|
| 17 |
libgomp1 \
|
|
|
|
| 20 |
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
|
| 22 |
# ── HF_TOKEN build arg ────────────────────────────────────────────
|
| 23 |
+
# Add HF_TOKEN to HF Space -> Settings -> Repository Secrets.
|
| 24 |
+
# HF Spaces passes Repository Secrets as Docker build ARGs automatically.
|
|
|
|
| 25 |
ARG HF_TOKEN=""
|
| 26 |
ENV HF_TOKEN=${HF_TOKEN}
|
| 27 |
|
|
|
|
| 35 |
RUN mkdir -p temp_uploads saved_images && chmod -R 777 temp_uploads saved_images
|
| 36 |
|
| 37 |
# ── Pre-download public models at BUILD time ──────────────────────
|
|
|
|
| 38 |
RUN python - <<'EOF'
|
| 39 |
import os, sys
|
| 40 |
|
|
|
|
| 65 |
print("All public models pre-downloaded successfully")
|
| 66 |
EOF
|
| 67 |
|
| 68 |
+
# ── Pre-download AdaFace (graceful — never fails the build) ───────
|
|
|
|
|
|
|
|
|
|
| 69 |
RUN python - <<'EOF'
|
| 70 |
import os, sys, traceback
|
| 71 |
|
|
|
|
| 75 |
|
| 76 |
if not HF_TOKEN:
|
| 77 |
print("HF_TOKEN not set - skipping AdaFace pre-download")
|
| 78 |
+
print("Fallback: ArcFace zero-padded to 1024-D (build succeeds)")
|
|
|
|
| 79 |
sys.exit(0)
|
| 80 |
|
| 81 |
try:
|
|
|
|
| 113 |
with torch.no_grad():
|
| 114 |
out = model(torch.zeros(1, 3, 112, 112))
|
| 115 |
emb = out if isinstance(out, torch.Tensor) else out.embedding
|
| 116 |
+
print("AdaFace done - output dim=" + str(emb.shape[-1]))
|
|
|
|
| 117 |
|
| 118 |
except Exception as e:
|
| 119 |
print("AdaFace pre-download failed: " + str(e))
|
| 120 |
print(traceback.format_exc()[-400:])
|
| 121 |
+
print("Build continues - ArcFace-only fallback active")
|
| 122 |
sys.exit(0)
|
| 123 |
EOF
|
| 124 |
|
| 125 |
EXPOSE 7860
|
| 126 |
|
|
|
|
| 127 |
ENV WEB_CONCURRENCY=1
|
| 128 |
|
| 129 |
CMD uvicorn main:app \
|
requirements.txt
CHANGED
|
@@ -12,6 +12,7 @@ torch==2.4.1+cpu
|
|
| 12 |
torchvision==0.19.1+cpu
|
| 13 |
|
| 14 |
# ── HuggingFace stack ─────────────────────────────────────────────
|
|
|
|
| 15 |
transformers
|
| 16 |
huggingface_hub>=0.26.0
|
| 17 |
safetensors>=0.4.0
|
|
@@ -19,6 +20,9 @@ tokenizers>=0.20.0
|
|
| 19 |
accelerate>=1.1.0
|
| 20 |
|
| 21 |
# ── InsightFace — SCRFD + ArcFace-R100 ───────────────────────────
|
|
|
|
|
|
|
|
|
|
| 22 |
insightface==0.7.3
|
| 23 |
onnxruntime==1.19.2
|
| 24 |
|
|
|
|
| 12 |
torchvision==0.19.1+cpu
|
| 13 |
|
| 14 |
# ── HuggingFace stack ─────────────────────────────────────────────
|
| 15 |
+
# transformers unpinned — let pip resolve to avoid conflicts with ultralytics
|
| 16 |
transformers
|
| 17 |
huggingface_hub>=0.26.0
|
| 18 |
safetensors>=0.4.0
|
|
|
|
| 20 |
accelerate>=1.1.0
|
| 21 |
|
| 22 |
# ── InsightFace — SCRFD + ArcFace-R100 ───────────────────────────
|
| 23 |
+
# insightface 0.7.3 has no pre-built wheel → pip tries to compile C++
|
| 24 |
+
# and fails without g++. Using 0.7.3 with g++ now added to Dockerfile.
|
| 25 |
+
# onnxruntime provides CPU ONNX inference for InsightFace models.
|
| 26 |
insightface==0.7.3
|
| 27 |
onnxruntime==1.19.2
|
| 28 |
|