# 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({
"24": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"32": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/wan2.7_i2v",
"format": "auto",
"format.codec": "auto",
"video": [
"33",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"33": {
"class_type": "Wan2ImageToVideoApi",
"inputs": {
"first_frame": [
"24",
0
],
"model": "wan2.7-i2v",
"model.duration": 5,
"model.negative_prompt": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走,字幕,文本",
"model.prompt": "The camera begins on a slow push-in toward the bearded man at the workbench, rain drumming steadily on the arched greenhouse glass behind him. Steam curls from the mug at his elbow and the low pendant lamp sways slightly on its cord, its pool of green-tinted light swinging across the scattered brass instruments. He lifts his gaze from the parchment, looks straight into the lens and speaks in a low, gravelly voice: \"Every one of these machines kept time for someone.\" He pauses, taps the zinc bench twice with one finger, and a faint metallic ticking begins somewhere in the shadows. The camera eases into a gentle arc to his left as a gust of wind rattles the windows and a few drops of water fall from the overhead pipes, glinting as they pass through the lamplight.",
"model.resolution": "720P",
"prompt_extend": True,
"seed": 1179774652,
"watermark": False
},
"_meta": {
"title": "Wan 2.7 Image to Video"
}
}
})
workflow.set_input("24", "image", client.assets.from_url("https://comfy.org/catalog-media/2e05c31e-a2dc-46f4-aec4-9002a61f4a62/504a46e1-44c3-452a-a39c-32d3d62dce19"))
# 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("32"):
output.to_file(output.name)