# 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({
"1": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_person_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Flux_VTO",
"images": [
"7",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"5": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_garment_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"6": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"1",
0
],
"image_b": [
"7",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"7": {
"class_type": "FluxVTONode",
"inputs": {
"garment": [
"5",
0
],
"person": [
"1",
0
],
"prompt": "Dress the woman from the person photo in the black leather moto jacket from the garment photo, worn open over her ivory sleeveless top so the top shows down the centre. Keep the jacket's asymmetric silver zip, notched lapels, press studs, slash pockets and its distressed, pebbled leather exactly as in the garment photo, sized naturally to her shoulders with the sleeves ending at her wrists. Keep her face, hair, pose, olive linen trousers, beige shoes, the concrete courtyard, the reflecting pool and the soft overcast light unchanged.",
"seed": 0
},
"_meta": {
"title": "Flux Virtual Try-On"
}
},
"9": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
}
})
workflow.set_input("5", "image", client.assets.from_url("https://comfy.org/catalog-media/0b1eb069-8108-4210-8625-4ba6004855d7/fd83852a-67ff-405e-9766-f7e72801e2b3"))
workflow.set_input("1", "image", client.assets.from_url("https://comfy.org/catalog-media/6773099b-1c89-4dac-a4d6-f9563a3c5709/2459b4be-9ce8-4fdb-8977-878f8bc3e2b7"))
# 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("4"):
output.to_file(output.name)