feat: harden pipeline UX — preprocess, rembg alpha, remix/lightbox

Downscale to 2000px JPEG before rembg, random blend opacity, timeout
retries, per-variant remix prefill, lightbox, and longer SFTP idle.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Frank Schwenk
2026-07-16 23:35:06 +02:00
parent 8ef123393a
commit 83d4468b69
16 changed files with 594 additions and 50 deletions
+18 -2
View File
@@ -38,18 +38,34 @@ FILTERS_JSON = ASSETS_DIR / "filters.json"
# --- Processing ----------------------------------------------------------
OUTPUT_COUNT = _int_env("OUTPUT_COUNT", 3)
# Fallback / remix default. Auto variants pick randomly in
# [BLEND_OPACITY_MIN, BLEND_OPACITY_MAX] instead.
BLEND_OPACITY = os.environ.get("BLEND_OPACITY", "30%")
BLEND_OPACITY_MIN = _int_env("BLEND_OPACITY_MIN", 10)
BLEND_OPACITY_MAX = _int_env("BLEND_OPACITY_MAX", 50)
FILTER_TIMEOUT = _int_env("FILTER_TIMEOUT", 120)
# Second-chance timeout for variants that hit FILTER_TIMEOUT during the
# normal pass — retried once at the end of the job (not during filter probes).
FILTER_TIMEOUT_LONG = _int_env("FILTER_TIMEOUT_LONG", 300)
MAX_FILTER_ATTEMPTS = _int_env("MAX_FILTER_ATTEMPTS", 8)
# Generous on purpose: the very first rembg call also downloads the ~176MB
# u2net model, which can take a while depending on the link.
# Longest edge after preprocess (ImageMagick). Keeps rembg/gmic sane on
# large camera JPEGs.
MAX_EDGE_PX = _int_env("MAX_EDGE_PX", 2000)
# Generous on purpose: the very first rembg call also downloads the model,
# which can take a while depending on the link.
REMBG_TIMEOUT = _int_env("REMBG_TIMEOUT", 600)
# birefnet-general OOMs on the ~8GB event box; u2net + alpha matting fits
# and is the practical equivalent of `rembg i -a`.
REMBG_MODEL = os.environ.get("REMBG_MODEL", "u2net")
REMBG_ALPHA = os.environ.get("REMBG_ALPHA", "1").strip().lower() in {"1", "true", "yes", "on"}
NICE_LEVEL = _int_env("NICE_LEVEL", 18)
# gmic CLI binary, override for local dev if not on PATH. rembg has no
# equivalent here — it runs via `python -m app.rembg_cli` (see pipeline.py
# run_rembg / app/rembg_cli.py), not a standalone binary.
GMIC_BIN = os.environ.get("GMIC_BIN", "gmic")
# ImageMagick binary (`magick` on IM7, `convert` on IM6). Empty = auto-detect.
MAGICK_BIN = os.environ.get("MAGICK_BIN", "")
# Fixed post-processing chain applied to every composed variant, ported
# verbatim from make_random.py.