fix: make the YOLO weights path configurable and drop a dead import

Adds YOLO_MODEL_PATH (default unchanged) and bakes the weights into
/tmp/Ultralytics in the image so a volume mounted over /app can't shadow
them, plus removes the redundant top-level scenedetect import.

Adapted from #47 by @kayceepeece, minus the CPU-only torch pin which
would conflict with the GPU production build.
This commit is contained in:
juancarlos.cavero 2026-08-20 18:51:39 +02:00
parent fea6364ffb
commit 8996ac9c1a
2 changed files with 8 additions and 4 deletions

View file

@ -102,8 +102,11 @@ RUN chown -R appuser:appuser /app /tmp/Ultralytics
# Switch to non-root user # Switch to non-root user
USER appuser USER appuser
# Pre-download YOLO model on build (now running as appuser) # Pre-download YOLO model on build (now running as appuser). Baked into
RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')" # /tmp/Ultralytics instead of the workdir so a volume mounted over /app can't
# shadow it and force a re-download at startup.
ENV YOLO_MODEL_PATH=/tmp/Ultralytics/yolov8n.pt
RUN python -c "from ultralytics import YOLO; YOLO('/tmp/Ultralytics/yolov8n.pt')"
# Expose FastAPI port # Expose FastAPI port
EXPOSE 8000 EXPOSE 8000

View file

@ -1,6 +1,5 @@
import time import time
import cv2 import cv2
import scenedetect
import subprocess import subprocess
import argparse import argparse
import re import re
@ -79,7 +78,9 @@ OUTPUT — RETURN ONLY VALID JSON (no markdown, no comments). Order clips by pre
""" """
# Load the YOLO model once (Keep for backup or scene analysis if needed) # Load the YOLO model once (Keep for backup or scene analysis if needed)
model = YOLO('yolov8n.pt') # YOLO_MODEL_PATH lets deployments point at a pre-downloaded weights file so a
# volume mounted over the workdir doesn't trigger a re-download at startup.
model = YOLO(os.environ.get("YOLO_MODEL_PATH", "yolov8n.pt"))
# --- MediaPipe Setup --- # --- MediaPipe Setup ---
# Use standard Face Detection (BlazeFace) for speed # Use standard Face Detection (BlazeFace) for speed