$ cat node-template.py

I

Image Upscale

// Upscales an image to higher resolution. Supports configurable scale factor.

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        scale_factor = float(inputs.get("scale_factor", 2.0))2122        if not image:23            raise ValueError("Image is required")24        if not (1.5 <= scale_factor <= 4.0):25            raise ValueError(f"Scale factor must be between 1.5 and 4.0, got {scale_factor}")2627        local_path = os.path.join(INPUT_DIR, image)28        if not os.path.exists(local_path):29            raise FileNotFoundError(f"Input image not found: {local_path}")3031        os.makedirs(OUTPUT_DIR, exist_ok=True)3233        print(34            f"Requesting upscale: scale={scale_factor}",35            file=sys.stderr,36        )3738        result = Gais.image.upscale(39            image=local_path,40            scale_factor=scale_factor,41        )4243        # Save result44        out_filename = "upscaled_result.png"45        out_path = os.path.join(OUTPUT_DIR, out_filename)46        with open(out_path, "wb") as f:47            f.write(result.content)4849        inference_time = result.metadata.get("inference_time_ms", "unknown")50        resolution = result.metadata.get("resolution", "unknown")51        print(52            f"Upscaled: scale={scale_factor}, resolution={resolution}, time={inference_time}ms",53            file=sys.stderr,54        )5556        # Probe output dimensions and emit aspect_ratio + resolution so57        # downstream nodes can chain.58        try:59            from PIL import Image60            with Image.open(out_path) as _im:61                _w, _h = _im.size62        except Exception:63            _w, _h = 0, 06465        output = {66            "image": out_filename,67            "aspect_ratio": round(_w / _h, 4) if _h else 0.0,68            "resolution": f"{_w}x{_h}",69        }70        print(json.dumps(output, indent=2))7172    except Exception as e:73        error_output = {74            "error": str(e),75            "errorType": type(e).__name__,76            "traceback": traceback.format_exc(),77        }78        print(json.dumps(error_output), file=sys.stderr)79        sys.exit(1)808182if __name__ == "__main__":83    main()

$ git log --oneline

v2.4.0
HEAD
2026-05-07
v2.3.12026-04-23
v2.1.02026-03-29
v2.0.02026-03-20