# 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": "Topaz",
"images": [
"11",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"8": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"2",
0
],
"image_b": [
"3",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"9": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"10",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"10": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"2",
0
],
"resize_type": "scale by multiplier",
"resize_type.multiplier": 1,
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"11": {
"class_type": "TopazImageEnhanceV2",
"inputs": {
"image": [
"2",
0
],
"model": "Reimagine",
"model.color_preservation": False,
"model.creativity": 3,
"model.crop_to_fill": False,
"model.face_enhancement": True,
"model.face_enhancement_creativity": 0,
"model.face_enhancement_strength": 1,
"model.face_preservation": True,
"model.prompt": "",
"model.subject_detection": "All",
"output_height": [
"9",
1
],
"output_width": [
"9",
0
]
},
"_meta": {
"title": "Topaz Image Enhance"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/b97b2e3f-76ec-496c-81ed-1a959741d7f3/fb114a60-c17f-450b-859c-2218be651f91"))
# 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)