# 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": "Flux2MaxImageNode",
"inputs": {
"height": [
"14",
1
],
"images": [
"15",
0
],
"prompt": "Replace the two mustard-yellow stools in front of the travertine breakfast bar in Image 1 with a single armchair exactly like the green velvet Victorian armchair in Image 2, keeping its carved mahogany frame, tufted emerald upholstery and brass casters. Place it facing the camera in front of the counter, at a natural scale for the room. Then seat the man from Image 3 in the armchair, relaxed, one arm resting on the armrest and legs crossed, wearing exactly the same rust velvet blazer, patterned shirt, brown flared trousers and platform boots, with the same face and hair. Keep the kitchen from Image 1 completely unchanged: the teak cabinets, green and terracotta tiles, orange refrigerator, copper pendant lamps, the bowl of persimmons, the terracotta floor, the window and the warm morning sunlight. Match the shadows and light on the chair and the man to the room.",
"prompt_upsampling": True,
"seed": 605236935620651,
"width": [
"14",
0
]
},
"_meta": {
"title": "Flux.2 [max] Image"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_scene_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_object_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"6": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Flux.2_max",
"images": [
"1",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"10": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_person_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"14": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"2",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"15": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"2",
0
],
"images.image1": [
"3",
0
],
"images.image2": [
"10",
0
]
},
"_meta": {
"title": "Batch Images"
}
}
})
workflow.set_input("3", "image", client.assets.from_url("https://comfy.org/catalog-media/64c1bfd4-464d-4cc9-ae35-c420b8bfeddd/43d99397-6ea4-40fe-afb2-a6fa8e344760"))
workflow.set_input("10", "image", client.assets.from_url("https://comfy.org/catalog-media/24acd8c3-8fc5-46d8-ae81-cd11a36d886b/9a29c56e-2ceb-4c3d-b9fa-4c4dacff4a07"))
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/4f9ff8de-3ce8-4e16-baa8-9a72972572e0/f4c98111-6bd3-468e-9fab-c3210ecf7e45"))
# 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("6"):
output.to_file(output.name)