mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: use MODELS_PATH env var for AI model paths instead of hardcoded /opt/models
The on-demand feature download system stores models at /data/ai/models/ (set via MODELS_PATH env var), but all Python scripts hardcoded /opt/models/ as the base path. Each script now reads MODELS_PATH and falls back to /opt/models for backward compatibility.
This commit is contained in:
@@ -17,23 +17,25 @@ def emit_progress(percent, stage):
|
||||
print(json.dumps({"progress": percent, "stage": stage}), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
DDCOLOR_MODEL_PATH = os.environ.get(
|
||||
"DDCOLOR_MODEL_PATH",
|
||||
"/opt/models/ddcolor/ddcolor.onnx",
|
||||
os.path.join(_MODELS_BASE, "ddcolor", "ddcolor.onnx"),
|
||||
)
|
||||
|
||||
# OpenCV DNN fallback model paths (lightweight ~17 MB)
|
||||
OPENCV_PROTO_PATH = os.environ.get(
|
||||
"OPENCV_COLORIZE_PROTO",
|
||||
"/opt/models/colorize-opencv/colorization_deploy_v2.prototxt",
|
||||
os.path.join(_MODELS_BASE, "colorize-opencv", "colorization_deploy_v2.prototxt"),
|
||||
)
|
||||
OPENCV_MODEL_PATH = os.environ.get(
|
||||
"OPENCV_COLORIZE_MODEL",
|
||||
"/opt/models/colorize-opencv/colorization_release_v2.caffemodel",
|
||||
os.path.join(_MODELS_BASE, "colorize-opencv", "colorization_release_v2.caffemodel"),
|
||||
)
|
||||
OPENCV_POINTS_PATH = os.environ.get(
|
||||
"OPENCV_COLORIZE_POINTS",
|
||||
"/opt/models/colorize-opencv/pts_in_hull.npy",
|
||||
os.path.join(_MODELS_BASE, "colorize-opencv", "pts_in_hull.npy"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ def emit_progress(percent, stage):
|
||||
|
||||
# ── Model path for new mp.tasks API ─────────────────────────────────
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
_FACE_DETECT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/latest/blaze_face_short_range.tflite"
|
||||
_DOCKER_MODEL_PATH = "/opt/models/mediapipe/blaze_face_short_range.tflite"
|
||||
_DOCKER_MODEL_PATH = os.path.join(_MODELS_BASE, "mediapipe", "blaze_face_short_range.tflite")
|
||||
_LOCAL_MODEL_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".models")
|
||||
_LOCAL_MODEL_PATH = os.path.join(_LOCAL_MODEL_DIR, "blaze_face_short_range.tflite")
|
||||
|
||||
|
||||
@@ -26,21 +26,23 @@ def emit_progress(percent, stage):
|
||||
print(json.dumps({"progress": percent, "stage": stage}), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
GFPGAN_MODEL_PATH = os.environ.get(
|
||||
"GFPGAN_MODEL_PATH",
|
||||
"/opt/models/gfpgan/GFPGANv1.3.pth",
|
||||
os.path.join(_MODELS_BASE, "gfpgan", "GFPGANv1.3.pth"),
|
||||
)
|
||||
|
||||
CODEFORMER_MODEL_PATH = os.environ.get(
|
||||
"CODEFORMER_MODEL_PATH",
|
||||
"/opt/models/codeformer/codeformer.pth",
|
||||
os.path.join(_MODELS_BASE, "codeformer", "codeformer.pth"),
|
||||
)
|
||||
|
||||
|
||||
# ── Model path for new mp.tasks API ─────────────────────────────────
|
||||
|
||||
_FACE_DETECT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/latest/blaze_face_short_range.tflite"
|
||||
_DOCKER_MODEL_PATH = "/opt/models/mediapipe/blaze_face_short_range.tflite"
|
||||
_DOCKER_MODEL_PATH = os.path.join(_MODELS_BASE, "mediapipe", "blaze_face_short_range.tflite")
|
||||
_LOCAL_MODEL_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".models")
|
||||
_LOCAL_MODEL_PATH = os.path.join(_LOCAL_MODEL_DIR, "blaze_face_short_range.tflite")
|
||||
|
||||
|
||||
@@ -78,8 +78,10 @@ def detect_with_solutions(img_array):
|
||||
|
||||
# ── New API: mp.tasks (mediapipe >= 0.10.30) ───────────────────────
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task"
|
||||
_DOCKER_MODEL_PATH = "/opt/models/mediapipe/face_landmarker.task"
|
||||
_DOCKER_MODEL_PATH = os.path.join(_MODELS_BASE, "mediapipe", "face_landmarker.task")
|
||||
MODEL_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".models")
|
||||
MODEL_PATH = os.path.join(MODEL_DIR, "face_landmarker.task")
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ def emit_progress(percent, stage):
|
||||
# Resolve the LaMa ONNX model path.
|
||||
# Docker places it at /opt/models/lama/lama_fp32.onnx.
|
||||
# For local dev, check a user-writable cache dir.
|
||||
LAMA_MODEL_DIR = os.environ.get("LAMA_MODEL_DIR", "/opt/models/lama")
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
LAMA_MODEL_DIR = os.environ.get("LAMA_MODEL_DIR", os.path.join(_MODELS_BASE, "lama"))
|
||||
LAMA_MODEL_PATH = os.path.join(LAMA_MODEL_DIR, "lama_fp32.onnx")
|
||||
LAMA_LOCAL_CACHE = os.path.join(os.path.expanduser("~"), ".cache", "ashim", "lama")
|
||||
LAMA_LOCAL_PATH = os.path.join(LAMA_LOCAL_CACHE, "lama_fp32.onnx")
|
||||
|
||||
@@ -9,15 +9,17 @@ def emit_progress(percent, stage):
|
||||
print(json.dumps({"progress": percent, "stage": stage}), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
# Model paths - Docker locations as defaults, with env var overrides
|
||||
SCUNET_MODEL_PATH = os.environ.get(
|
||||
"SCUNET_MODEL_PATH",
|
||||
"/opt/models/scunet/scunet_color_real_psnr.pth",
|
||||
os.path.join(_MODELS_BASE, "scunet", "scunet_color_real_psnr.pth"),
|
||||
)
|
||||
|
||||
NAFNET_MODEL_PATH = os.environ.get(
|
||||
"NAFNET_MODEL_PATH",
|
||||
"/opt/models/nafnet/NAFNet-SIDD-width64.pth",
|
||||
os.path.join(_MODELS_BASE, "nafnet", "NAFNet-SIDD-width64.pth"),
|
||||
)
|
||||
|
||||
# Local cache for dev installs
|
||||
|
||||
@@ -11,8 +11,10 @@ def emit_progress(percent, stage):
|
||||
|
||||
# ── Model path for new mp.tasks API ─────────────────────────────────
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
_FACE_MESH_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task"
|
||||
_DOCKER_MODEL_PATH = "/opt/models/mediapipe/face_landmarker.task"
|
||||
_DOCKER_MODEL_PATH = os.path.join(_MODELS_BASE, "mediapipe", "face_landmarker.task")
|
||||
_LOCAL_MODEL_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".models")
|
||||
_LOCAL_MODEL_PATH = os.path.join(_LOCAL_MODEL_DIR, "face_landmarker.task")
|
||||
|
||||
|
||||
@@ -22,12 +22,14 @@ def emit_progress(percent, stage):
|
||||
|
||||
# ── Model paths ───────────────────────────────────────────────────────
|
||||
|
||||
LAMA_MODEL_DIR = os.environ.get("LAMA_MODEL_DIR", "/opt/models/lama")
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
LAMA_MODEL_DIR = os.environ.get("LAMA_MODEL_DIR", os.path.join(_MODELS_BASE, "lama"))
|
||||
LAMA_MODEL_PATH = os.path.join(LAMA_MODEL_DIR, "lama_fp32.onnx")
|
||||
LAMA_LOCAL_CACHE = os.path.join(os.path.expanduser("~"), ".cache", "ashim", "lama")
|
||||
LAMA_LOCAL_PATH = os.path.join(LAMA_LOCAL_CACHE, "lama_fp32.onnx")
|
||||
|
||||
CODEFORMER_MODEL_DIR = os.environ.get("CODEFORMER_MODEL_DIR", "/opt/models/codeformer")
|
||||
CODEFORMER_MODEL_DIR = os.environ.get("CODEFORMER_MODEL_DIR", os.path.join(_MODELS_BASE, "codeformer"))
|
||||
CODEFORMER_MODEL_PATH = os.path.join(CODEFORMER_MODEL_DIR, "codeformer.onnx")
|
||||
CODEFORMER_LOCAL_CACHE = os.path.join(
|
||||
os.path.expanduser("~"), ".cache", "ashim", "codeformer"
|
||||
@@ -35,7 +37,7 @@ CODEFORMER_LOCAL_CACHE = os.path.join(
|
||||
CODEFORMER_LOCAL_PATH = os.path.join(CODEFORMER_LOCAL_CACHE, "codeformer.onnx")
|
||||
|
||||
DDCOLOR_MODEL_PATH = os.environ.get(
|
||||
"DDCOLOR_MODEL_PATH", "/opt/models/ddcolor/ddcolor.onnx"
|
||||
"DDCOLOR_MODEL_PATH", os.path.join(_MODELS_BASE, "ddcolor", "ddcolor.onnx")
|
||||
)
|
||||
|
||||
LAMA_MODEL_SIZE = 512
|
||||
@@ -220,7 +222,7 @@ def _get_codeformer_path():
|
||||
# ── Model path for new mp.tasks API ─────────────────────────────────
|
||||
|
||||
_FACE_DETECT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/latest/blaze_face_short_range.tflite"
|
||||
_FACE_DETECT_DOCKER_PATH = "/opt/models/mediapipe/blaze_face_short_range.tflite"
|
||||
_FACE_DETECT_DOCKER_PATH = os.path.join(_MODELS_BASE, "mediapipe", "blaze_face_short_range.tflite")
|
||||
_FACE_DETECT_LOCAL_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", ".models")
|
||||
_FACE_DETECT_LOCAL_PATH = os.path.join(_FACE_DETECT_LOCAL_DIR, "blaze_face_short_range.tflite")
|
||||
|
||||
|
||||
@@ -26,14 +26,16 @@ def emit_progress(percent, stage):
|
||||
print(json.dumps({"progress": percent, "stage": stage}), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
_MODELS_BASE = os.environ.get("MODELS_PATH", "/opt/models")
|
||||
|
||||
REALESRGAN_MODEL_PATH = os.environ.get(
|
||||
"REALESRGAN_MODEL_PATH",
|
||||
"/opt/models/realesrgan/RealESRGAN_x4plus.pth",
|
||||
os.path.join(_MODELS_BASE, "realesrgan", "RealESRGAN_x4plus.pth"),
|
||||
)
|
||||
|
||||
GFPGAN_MODEL_PATH = os.environ.get(
|
||||
"GFPGAN_MODEL_PATH",
|
||||
"/opt/models/gfpgan/GFPGANv1.3.pth",
|
||||
os.path.join(_MODELS_BASE, "gfpgan", "GFPGANv1.3.pth"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user