# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"1": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "seedvr2_after/image",
"images": [
"66:59",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"65": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"1",
0
],
"image_b": [
"9",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"66:48": {
"class_type": "VAEEncodeTiled",
"inputs": {
"overlap": 128,
"pixels": [
"66:58",
0
],
"temporal_overlap": 8,
"temporal_size": 4096,
"tile_size": 512,
"vae": [
"66:51",
0
]
},
"_meta": {
"title": "VAE Encode (Tiled)"
}
},
"66:50": {
"class_type": "JoinImageWithAlpha",
"inputs": {
"alpha": [
"1",
1
],
"image": [
"1",
0
]
},
"_meta": {
"title": "Join Image with Alpha"
}
},
"66:51": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "seedvr2_ema_vae_fp16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"66:52": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "seedvr2_7b_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"66:54": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"66:48",
0
],
"model": [
"66:52",
0
],
"negative": [
"66:61",
1
],
"positive": [
"66:61",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 959948902156062,
"steps": 1
},
"_meta": {
"title": "KSampler"
}
},
"66:55": {
"class_type": "VAEDecodeTiled",
"inputs": {
"overlap": 128,
"samples": [
"66:54",
0
],
"temporal_overlap": 8,
"temporal_size": 4096,
"tile_size": 512,
"vae": [
"66:51",
0
]
},
"_meta": {
"title": "VAE Decode (Tiled)"
}
},
"66:57": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"66:50",
0
],
"resize_type": "scale by multiplier",
"resize_type.multiplier": 4,
"scale_method": "lanczos"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"66:58": {
"class_type": "SeedVR2Preprocess",
"inputs": {
"resized_images": [
"66:57",
0
]
},
"_meta": {
"title": "Pre-Process SeedVR2 Input"
}
},
"66:59": {
"class_type": "SeedVR2PostProcessing",
"inputs": {
"color_correction_method": "none",
"images": [
"66:55",
0
],
"original_resized_images": [
"66:57",
0
]
},
"_meta": {
"title": "Post-Process SeedVR2 Output"
}
},
"66:61": {
"class_type": "SeedVR2Conditioning",
"inputs": {
"model": [
"66:52",
0
],
"vae_conditioning": [
"66:48",
0
]
},
"_meta": {
"title": "Apply SeedVR2 Conditioning"
}
}
})
workflow.set_input("1", "image", client.assets.from_url("https://comfy.org/catalog-media/bab04b85-4b07-408b-ad94-2dcfad40b240/4fea2a72-0dc0-468e-b736-c495c50b8ca4"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("9"):
output.to_file(output.name)