# 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({
"10": {
"class_type": "SaveAudioAdvanced",
"inputs": {
"audio": [
"33:9",
0
],
"filename_prefix": "audio/YuE2",
"format": "flac"
},
"_meta": {
"title": "Save Audio (Advanced)"
}
},
"33:14": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"33:30",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"33:15": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "yue2_3b_int8_convrot.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"33:18": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"33:25",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"33:23": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"33:25",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"33:24": {
"class_type": "YuE2GenerateABC",
"inputs": {
"clip": [
"33:15",
1
],
"lyrics": [
"33:37",
0
],
"max_abc_tokens": 8192,
"mode": "full",
"penalty_window": 100,
"repetition_penalty": 1.005,
"seed": [
"33:34",
0
],
"style": [
"33:36",
0
],
"temperature": 0.7,
"top_k": 30,
"top_p": 0.9
},
"_meta": {
"title": "YuE2 Generate ABC"
}
},
"33:25": {
"class_type": "YuE2GenerateMusic",
"inputs": {
"abc": [
"33:14",
0
],
"cfg_scale": 1,
"clip": [
"33:15",
1
],
"lyrics": [
"33:37",
0
],
"max_duration": 120,
"mode": "full",
"repetition_penalty": 1.2,
"seed": [
"33:34",
0
],
"style": [
"33:36",
0
],
"temperature": 1,
"top_k": 100,
"top_p": 0.95
},
"_meta": {
"title": "YuE2 Generate Music"
}
},
"33:30": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"33:32",
0
],
"on_true": [
"33:24",
0
],
"switch": [
"33:31",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"33:31": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": True
},
"_meta": {
"title": "Boolean (ABC planning)"
}
},
"33:32": {
"class_type": "PrimitiveString",
"inputs": {
"value": ""
},
"_meta": {
"title": "Text (Empty ABC)"
}
},
"33:34": {
"class_type": "SeedNode",
"inputs": {
"seed": 0
},
"_meta": {
"title": "Seed"
}
},
"33:36": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Upbeat indie pop with warm female vocals, bright electric guitars, punchy drums, melodic bass, and subtle synth layers. Catchy and energetic, with an uplifting summer atmosphere, a memorable chorus, and polished modern production."
},
"_meta": {
"title": "Text (Style)"
}
},
"33:37": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "[Verse]\nMorning light across the window\nCity waking down below\nI can hear the streets are calling\nFeels like somewhere we should go\n\n[Chorus]\nRun with me into the sunlight\nLeave the shadows far behind\nWe don't need to know tomorrow\nTonight the whole world feels alive\n\n[Verse]\nRadio playing through the open door\nLaughing like we did before\nEvery mile becomes a memory\nAnd I just want a little more\n\n[Chorus]\nRun with me into the sunlight\nLeave the shadows far behind\nWe don't need to know tomorrow\nTonight the whole world feels alive"
},
"_meta": {
"title": "Text (Lyrics)"
}
},
"33:5": {
"class_type": "EmptyYuE2LatentAudio",
"inputs": {
"batch_size": 1,
"seconds": [
"33:25",
1
]
},
"_meta": {
"title": "Empty YuE2 Latent Audio"
}
},
"33:8": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"33:5",
0
],
"model": [
"33:15",
0
],
"negative": [
"33:18",
0
],
"positive": [
"33:25",
0
],
"sampler_name": "dpm_2",
"scheduler": "sgm_uniform",
"seed": [
"33:34",
0
],
"steps": 32
},
"_meta": {
"title": "KSampler"
}
},
"33:9": {
"class_type": "VAEDecodeAudio",
"inputs": {
"samples": [
"33:8",
0
],
"vae": [
"33:15",
2
]
},
"_meta": {
"title": "VAE Decode Audio"
}
}
})
# 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("10"):
output.to_file(output.name)