# 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({
"703": {
"class_type": "SoniloVideoToMusic",
"inputs": {
"prompt": "Sense of absurdity, a leopard sprinting at full speed in the wilderness, silent film, comedy",
"seed": 0,
"video": [
"705",
0
]
},
"_meta": {
"title": "Sonilo Video to Music"
}
},
"705": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"708": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Sonilo",
"format": "auto",
"format.codec": "auto",
"video": [
"724:718",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"728": {
"class_type": "SaveAudioAdvanced",
"inputs": {
"audio": [
"703",
0
],
"filename_prefix": "audio/Sonilo",
"format": "mp3",
"format.quality": "V0"
},
"_meta": {
"title": "Save Audio (Advanced)"
}
},
"724:717": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"705",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"724:718": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"724:721",
0
],
"bit_depth": 8,
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"724:717",
2
],
"images": [
"724:717",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"724:719": {
"class_type": "AudioAdjustVolume",
"inputs": {
"audio": [
"728",
0
],
"volume": 1
},
"_meta": {
"title": "Adjust Audio Volume"
}
},
"724:721": {
"class_type": "AudioMerge",
"inputs": {
"audio1": [
"724:722",
0
],
"audio2": [
"724:719",
0
],
"merge_method": "add"
},
"_meta": {
"title": "Merge Audio"
}
},
"724:722": {
"class_type": "AudioAdjustVolume",
"inputs": {
"audio": [
"724:717",
1
],
"volume": 1
},
"_meta": {
"title": "Adjust Audio Volume"
}
}
})
workflow.set_input("705", "file", client.assets.from_url("https://comfy.org/catalog-media/b4a2f42c-d1b5-4f4d-a73e-d183da5d0303/18a09872-067c-4882-b2ca-63c216858eb4"))
# 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("708"):
output.to_file(output.name)