# 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_cover",
"format": "flac"
},
"_meta": {
"title": "Save Audio (Advanced)"
}
},
"45": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_audio_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"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:25": {
"class_type": "YuE2GenerateMusic",
"inputs": {
"abc": [
"33:44",
0
],
"cfg_scale": 1,
"clip": [
"33:15",
1
],
"lyrics": "[Verse]\nStreetlights shimmer on the pavement\nMidnight breathing soft and slow\nEvery corner holds a memory\nOf the places we used to know\n\n[Chorus]\nStay with me until the morning\nLet the city fade away\nWe don't need to chase tomorrow\nAll I need is here today\n\n[Verse]\nOld café beneath the neon\nRain is falling on the glass\nEvery song becomes a story\nEvery moment moves too fast\n\n[Chorus]\nStay with me until the morning\nLet the city fade away\nWe don't need to chase tomorrow\nAll I need is here today\n\n[Bridge]\nMaybe time will keep on turning\nMaybe everything will change\nBut tonight the music holds us\nLike a fire inside the rain\n\n[Chorus]\nStay with me until the morning\nLet the city fade away\nWe don't need to chase tomorrow\nAll I need is here today",
"max_duration": 360,
"mode": "melody",
"repetition_penalty": 1.2,
"seed": [
"33:34",
0
],
"style": "English, soulful jazz-pop, expressive male vocal, relaxed 88 BPM, Rhodes piano, upright bass, brushed drums, warm saxophone, subtle strings, intimate late-night atmosphere, rich and organic live-band production",
"temperature": 1,
"top_k": 100,
"top_p": 0.95
},
"_meta": {
"title": "YuE2 Generate Music"
}
},
"33:34": {
"class_type": "SeedNode",
"inputs": {
"seed": 0
},
"_meta": {
"title": "Seed"
}
},
"33:41": {
"class_type": "SheetSage2AudioToABC",
"inputs": {
"audio": [
"45",
0
],
"audio_encoder": [
"33:43",
0
],
"mode": "melody"
},
"_meta": {
"title": "SheetSage2 Audio to ABC"
}
},
"33:43": {
"class_type": "AudioEncoderLoader",
"inputs": {
"audio_encoder_name": "sheetsage2_bf16.safetensors"
},
"_meta": {
"title": "Load Audio Encoder"
}
},
"33:44": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"33:41",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"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"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("45", "audio", client.assets.from_url("https://example.com/replace-with-a-url/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)