AdarshDRC commited on
Commit
ccf2e38
·
verified ·
1 Parent(s): 6bd9d26

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -13
Dockerfile CHANGED
@@ -1,16 +1,15 @@
1
  # Dockerfile
2
 
3
-
4
  FROM python:3.10-slim
5
 
6
  WORKDIR /app
7
 
8
- # ── System deps (OpenCV headless needs libGL) ────────────────────
9
  RUN apt-get update && apt-get install -y --no-install-recommends \
10
  libgl1 libglib2.0-0 libgomp1 git \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # ── Python deps ──────────────────────────────────────────────────
14
  COPY requirements.txt .
15
  RUN pip install --no-cache-dir --compile -r requirements.txt
16
 
@@ -19,10 +18,8 @@ COPY . .
19
 
20
  RUN mkdir -p temp_uploads saved_images && chmod -R 777 temp_uploads saved_images
21
 
22
- # ── Pre-download all AI models at BUILD time ─────────────────────
23
- # This bakes the weights into the Docker image layer.
24
- # Cold-start on HF Spaces goes from ~3-5 min → ~10 sec.
25
- # Remove this block if your image size budget is tight (<5 GB limit on free HF).
26
  RUN python - <<'EOF'
27
  from transformers import AutoProcessor, AutoModel, AutoImageProcessor
28
  from ultralytics import YOLO
@@ -37,8 +34,8 @@ print("Pre-downloading DINOv2 …")
37
  AutoImageProcessor.from_pretrained("facebook/dinov2-base")
38
  AutoModel.from_pretrained("facebook/dinov2-base")
39
 
40
- print("Pre-downloading YOLO …")
41
- YOLO("yolo11n.pt")
42
 
43
  print("Pre-downloading GhostFaceNet + RetinaFace …")
44
  dummy = np.zeros((112, 112, 3), dtype=np.uint8)
@@ -46,16 +43,16 @@ try:
46
  DeepFace.represent(img_path=dummy, model_name="GhostFaceNet",
47
  detector_backend="retinaface", enforce_detection=False)
48
  except Exception:
49
- pass # first run just downloads weights; inference error is fine here
50
 
51
  print("✅ All models cached in image layer")
52
  EOF
53
 
54
  EXPOSE 7860
55
 
56
- # ── Two uvicorn workers for true parallelism ─────────────────────
57
- # WEB_CONCURRENCY can be overridden via HF Space env vars
58
- ENV WEB_CONCURRENCY=2
59
 
60
  CMD uvicorn main:app \
61
  --host 0.0.0.0 \
 
1
  # Dockerfile
2
 
 
3
  FROM python:3.10-slim
4
 
5
  WORKDIR /app
6
 
7
+ # ── System deps ──────────────────────────────────────────────────
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
  libgl1 libglib2.0-0 libgomp1 git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # ── Python deps ──────────────────────────────────────────────────
13
  COPY requirements.txt .
14
  RUN pip install --no-cache-dir --compile -r requirements.txt
15
 
 
18
 
19
  RUN mkdir -p temp_uploads saved_images && chmod -R 777 temp_uploads saved_images
20
 
21
+ # ── Pre-download ALL AI models at BUILD time ─────────────────────
22
+ # Bakes weights into Docker image layer → cold start ~10 sec not 5 min
 
 
23
  RUN python - <<'EOF'
24
  from transformers import AutoProcessor, AutoModel, AutoImageProcessor
25
  from ultralytics import YOLO
 
34
  AutoImageProcessor.from_pretrained("facebook/dinov2-base")
35
  AutoModel.from_pretrained("facebook/dinov2-base")
36
 
37
+ print("Pre-downloading YOLO (seg model) …")
38
+ YOLO("yolo11n-seg.pt") # ← FIXED: was yolo11n.pt, now yolo11n-seg.pt
39
 
40
  print("Pre-downloading GhostFaceNet + RetinaFace …")
41
  dummy = np.zeros((112, 112, 3), dtype=np.uint8)
 
43
  DeepFace.represent(img_path=dummy, model_name="GhostFaceNet",
44
  detector_backend="retinaface", enforce_detection=False)
45
  except Exception:
46
+ pass # first run just downloads weights; inference error is fine
47
 
48
  print("✅ All models cached in image layer")
49
  EOF
50
 
51
  EXPOSE 7860
52
 
53
+ # ── Single worker models are already in memory, no need for 2 ──
54
+ # 2 workers was causing both to re-download yolo11n-seg.pt simultaneously
55
+ ENV WEB_CONCURRENCY=1
56
 
57
  CMD uvicorn main:app \
58
  --host 0.0.0.0 \