# 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({
"5": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"8": {
"class_type": "DrawBBoxes",
"inputs": {
"bboxes": [
"33:11",
1
],
"image": [
"5",
0
]
},
"_meta": {
"title": "Draw BBoxes"
}
},
"19": {
"class_type": "MediaPipeFaceMeshVisualize",
"inputs": {
"color": "#00ff40",
"connections": "all",
"face_landmarks": [
"33:11",
0
],
"image": [
"5",
0
],
"point_size": 2,
"thickness": 1
},
"_meta": {
"title": "Visualize Face Landmarks (MediaPipe)"
}
},
"27": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"19",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"29": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"8",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"34": {
"class_type": "MaskPreview",
"inputs": {
"mask": [
"33:20",
0
]
},
"_meta": {
"title": "Preview Mask"
}
},
"33:11": {
"class_type": "MediaPipeFaceLandmarker",
"inputs": {
"detector_variant": "full",
"face_detection_model": [
"33:2",
0
],
"image": [
"5",
0
],
"min_confidence": 0.5,
"missing_frame_fallback": "empty",
"num_faces": 0
},
"_meta": {
"title": "Detect Face Landmarks (MediaPipe)"
}
},
"33:2": {
"class_type": "LoadMediaPipeFaceLandmarker",
"inputs": {
"model_name": "mediapipe_face_fp32.safetensors"
},
"_meta": {
"title": "Load Face Detection Model (MediaPipe)"
}
},
"33:20": {
"class_type": "MediaPipeFaceMask",
"inputs": {
"face_landmarks": [
"33:11",
0
],
"regions": "custom",
"regions.face_oval": True,
"regions.irises": False,
"regions.left_eye": False,
"regions.lips": False,
"regions.right_eye": False
},
"_meta": {
"title": "Draw Face Mask (MediaPipe)"
}
}
})
workflow.set_input("5", "image", client.assets.from_url("https://comfy.org/catalog-media/238a07fd-3a90-4e9a-b6db-1739b3e8f333/f001eff6-382f-4aa9-b6d2-93fd0833f8f4"))
# 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("29"):
output.to_file(output.name)