$ cat node-template.py
I
Image Remove Background
// Removes the background from an image. Outputs a transparent PNG.
Process
Image
template.py
1import os2import sys3import json4import traceback56from gais import Gais78INPUT_DIR = "/data/input"9OUTPUT_DIR = "/data/output"101112def main():13 try:14 input_json = sys.stdin.read()15 execution_input = json.loads(input_json)16 inputs = execution_input.get("inputs", {})17 service_defaults = execution_input.get("service_defaults", {})1819 image = inputs.get("image", "")20 if not image:21 raise ValueError("Input image is required")2223 local_path = os.path.join(INPUT_DIR, image)24 if not os.path.exists(local_path):25 raise FileNotFoundError(f"Input image not found: {local_path}")2627 os.makedirs(OUTPUT_DIR, exist_ok=True)2829 result = Gais.image.remove_bg(30 image=local_path,31 )3233 # Save result34 out_filename = "removebg_result.png"35 out_path = os.path.join(OUTPUT_DIR, out_filename)36 with open(out_path, "wb") as f:37 f.write(result.content)3839 inference_time = result.metadata.get("inference_time_ms", "unknown")40 print(f"Background removed: time={inference_time}ms", file=sys.stderr)4142 # Probe output dimensions and emit aspect_ratio + resolution so43 # downstream nodes can chain.44 try:45 from PIL import Image46 with Image.open(out_path) as _im:47 _w, _h = _im.size48 except Exception:49 _w, _h = 0, 05051 output = {52 "image": out_filename,53 "aspect_ratio": round(_w / _h, 4) if _h else 0.0,54 "resolution": f"{_w}x{_h}",55 }56 print(json.dumps(output, indent=2))5758 except Exception as e:59 error_output = {60 "error": str(e),61 "errorType": type(e).__name__,62 "traceback": traceback.format_exc(),63 }64 print(json.dumps(error_output), file=sys.stderr)65 sys.exit(1)666768if __name__ == "__main__":69 main()$ git log --oneline
v1.3.0
HEAD
2026-05-07v1.2.22026-04-23
v1.0.02026-04-09