# 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({
"16": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"19",
1
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": [
"19",
2
],
"images": [
"15:4",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"17": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/SeedVR2",
"format": "auto",
"format.codec": "auto",
"video": [
"16",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"19": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"27",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"27": {
"class_type": "Video Slice",
"inputs": {
"duration": 5,
"start_time": 0,
"strict_duration": False,
"video": [
"39",
0
]
},
"_meta": {
"title": "Trim Video"
}
},
"36": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"19",
0
],
"resize_type": "scale longer dimension",
"resize_type.longer_size": 1280,
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"38": {
"class_type": "VHS_LoadVideo",
"inputs": {
"choose video to upload": "image",
"custom_height": 0,
"custom_width": 0,
"force_rate": 30,
"format": "AnimateDiff",
"frame_load_cap": 0,
"select_every_nth": 1,
"skip_first_frames": 0,
"video": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video (Upload) 🎥🅥🅗🅢"
}
},
"39": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"38",
2
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": [
"40",
0
],
"images": [
"38",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"40": {
"class_type": "VHS_VideoInfo",
"inputs": {
"video_info": [
"38",
3
]
},
"_meta": {
"title": "Video Info 🎥🅥🅗🅢"
}
},
"15:4": {
"class_type": "SeedVR2VideoUpscaler",
"inputs": {
"batch_size": 5,
"color_correction": "lab",
"dit": [
"15:5",
0
],
"enable_debug": False,
"image": [
"36",
0
],
"input_noise_scale": 0,
"latent_noise_scale": 0,
"max_resolution": 0,
"offload_device": "cpu",
"prepend_frames": 0,
"resolution": 1080,
"seed": 3566763637,
"temporal_overlap": 0,
"uniform_batch_size": False,
"vae": [
"15:6",
0
]
},
"_meta": {
"title": "SeedVR2 Video Upscaler (v2.5.24)"
}
},
"15:5": {
"class_type": "SeedVR2LoadDiTModel",
"inputs": {
"attention_mode": "sdpa",
"blocks_to_swap": 0,
"cache_model": False,
"device": "cuda:0",
"model": "seedvr2_ema_7b_fp16.safetensors",
"offload_device": "none",
"swap_io_components": False
},
"_meta": {
"title": "SeedVR2 (Down)Load DiT Model"
}
},
"15:6": {
"class_type": "SeedVR2LoadVAEModel",
"inputs": {
"cache_model": False,
"decode_tile_overlap": 128,
"decode_tile_size": 1024,
"decode_tiled": False,
"device": "cuda:0",
"encode_tile_overlap": 128,
"encode_tile_size": 1024,
"encode_tiled": False,
"model": "ema_vae_fp16.safetensors",
"offload_device": "none",
"tile_debug": "false"
},
"_meta": {
"title": "SeedVR2 (Down)Load VAE Model"
}
}
})
workflow.set_input("38", "video", client.assets.from_url("https://comfy.org/catalog-media/e2a93010-f5a0-403a-91f8-74472a9c8c5f/bc5ce2fb-7782-4434-b83f-c46b94c5d6db"))
# 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("17"):
output.to_file(output.name)