# 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": "HeyGenDecisionScore",
"inputs": {
"images.image_1": [
"3",
0
],
"model": "heygen-decision-1",
"question": "Rate the technical quality of the image from 1 (worst) to 10 (best).",
"threshold": 6
},
"_meta": {
"title": "HeyGen Decision (Score)"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "cartoon_kid_inventor.png"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "LoadImage",
"inputs": {
"image": "tiefling_sorcerer.png"
},
"_meta": {
"title": "Load Image"
}
},
"7": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"2",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"8": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"2",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"9": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a > b",
"values.a": [
"2",
1
],
"values.b": [
"15",
1
]
},
"_meta": {
"title": "Math Expression"
}
},
"12": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"4",
0
],
"on_true": [
"3",
0
],
"switch": [
"9",
2
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"14": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"12",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"15": {
"class_type": "HeyGenDecisionScore",
"inputs": {
"images.image_1": [
"4",
0
],
"model": "heygen-decision-1",
"question": "Rate the technical quality of the image from 1 (worst) to 10 (best).",
"threshold": 6
},
"_meta": {
"title": "HeyGen Decision (Score)"
}
},
"16": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"21",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"17": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"21",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"18": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"21",
2
]
},
"_meta": {
"title": "Preview as Text"
}
},
"19": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"15",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"20": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"15",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"21": {
"class_type": "HeyGenDecisionYesNo",
"inputs": {
"images.image_1": [
"3",
0
],
"model": "heygen-decision-1",
"question": "Is there a person in the image?",
"threshold": 0.5
},
"_meta": {
"title": "HeyGen Decision (Yes/No)"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)