# 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": "TopazImageEnhance",
"inputs": {
"color_preservation": False,
"creativity": 3,
"crop_to_fill": False,
"face_enhancement": True,
"face_enhancement_creativity": 0,
"face_enhancement_strength": 1,
"face_preservation": True,
"image": [
"2",
0
],
"model": "Reimagine",
"output_height": [
"5",
0
],
"output_width": [
"4",
0
],
"prompt": "Restore this faded 1970s family snapshot of an elderly woman waving in an autumn apple orchard. Recover sharp, natural detail in her face, her knitted wool cardigan, floral apron, corduroy trousers and rubber boots, and in the twisted apple branches, fallen fruit, dry grass and split-rail fence behind her. Correct the yellow-magenta colour shift into warm, believable autumn tones and lift the hazy sky, but keep the gentle look of a real photograph from that decade with a light, fine film grain. Do not change her expression, pose, clothing or the layout of the orchard; only make the image clearer, cleaner and more defined.",
"subject_detection": "All"
},
"_meta": {
"title": "Topaz Image Enhance (Legacy)"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Topaz",
"images": [
"1",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"4": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 1920
},
"_meta": {
"title": "output_width"
}
},
"5": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 1080
},
"_meta": {
"title": "output_height"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/2674ac8f-8c4e-4d10-983c-de5d879bb31e/e9e88455-59f5-43e1-9e36-8d6f01696439"))
# 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)