# 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({
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"5",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"4": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": {
"__value__": [
"",
""
]
},
"image_a": [
"2",
0
],
"image_b": [
"5",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"5": {
"class_type": "MagnificImageUpscalerPreciseV2Node",
"inputs": {
"auto_downscale": True,
"flavor": "photo",
"image": [
"2",
0
],
"scale_factor": "2x",
"sharpen": 7,
"smart_grain": 7,
"ultra_detail": 30
},
"_meta": {
"title": "Magnific Image Upscale (Precise V2)"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/d79573da-0623-4930-bb66-fc88afebc904/8fadb501-144f-4df0-8afd-5ef2dbb5b15d"))
# 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("3"):
output.to_file(output.name)