From 8996ac9c1a84dfcf12e8f197d397a5ff6babb5e8 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Thu, 20 Aug 2026 18:51:39 +0200 Subject: [PATCH] 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. --- Dockerfile | 7 +++++-- main.py | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7fc111d..6bbf860 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,8 +102,11 @@ RUN chown -R appuser:appuser /app /tmp/Ultralytics # Switch to non-root user USER appuser -# Pre-download YOLO model on build (now running as appuser) -RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')" +# Pre-download YOLO model on build (now running as appuser). Baked into +# /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 8000 diff --git a/main.py b/main.py index 0e0e6aa..5ccea2d 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,5 @@ import time import cv2 -import scenedetect import subprocess import argparse 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) -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 --- # Use standard Face Detection (BlazeFace) for speed