"""Minimal `rembg` runner, invoked as its own subprocess.
We deliberately don't shell out to the official `rembg` CLI: that needs
the `rembg[cli]` extra (aiohttp, gradio, watchdog, ...) just to run a
single background removal. Calling the `remove()` API directly from a
tiny script keeps the image smaller while still giving pipeline.py a
subprocess boundary to apply `nice` and a hard timeout to.
Defaults target the event box (≈8GB RAM): u2net + alpha matting.
`birefnet-general` (~928MB weights) OOMs here; override via REMBG_MODEL
/ REMBG_ALPHA if the host has more headroom.
"""
from __future__ import annotations
import os
import sys
import traceback
from pathlib import Path
def _env_bool(name: str, default: bool) -> bool:
raw = os.environ.get(name)
if raw is None:
return default
return raw.strip().lower() in {"1", "true", "yes", "on"}
def main() -> int:
if len(sys.argv) != 3:
print("usage: python -m app.rembg_cli