refactor: align seam_carve.py with sidecar script conventions

This commit is contained in:
Siddharth Kumar Sah
2026-04-07 23:25:40 +08:00
parent 1460ab7a4a
commit 18119166f0
+17 -4
View File
@@ -13,16 +13,17 @@ Args:
import json
import sys
import numpy as np
from PIL import Image
def emit_progress(percent, stage):
print(json.dumps({"progress": int(percent), "stage": stage}), file=sys.stderr, flush=True)
"""Emit structured progress to stderr for bridge.ts to capture."""
print(json.dumps({"progress": percent, "stage": stage}), file=sys.stderr, flush=True)
def build_face_mask(img_array):
"""Detect faces with MediaPipe and return a boolean keep_mask."""
import numpy as np
try:
import mediapipe as mp
except ImportError:
@@ -71,12 +72,24 @@ def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
settings = json.loads(sys.argv[3])
try:
settings = json.loads(sys.argv[3])
except (json.JSONDecodeError, ValueError):
print(json.dumps({"success": False, "error": "Invalid settings JSON"}))
sys.exit(1)
target_width = settings.get("width")
target_height = settings.get("height")
protect_faces = settings.get("protectFaces", False)
try:
import numpy as np
from PIL import Image
except ImportError:
print(json.dumps({"success": False, "error": "Pillow/numpy not installed"}))
sys.exit(1)
try:
import seam_carving
except ImportError: