# 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({
"7": {
"class_type": "SaveGLB",
"inputs": {
"filename_prefix": "3d/Moge",
"mesh": [
"29:24",
0
]
},
"_meta": {
"title": "Save 3D Model"
}
},
"28": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"29:24": {
"class_type": "MoGePointMapToMesh",
"inputs": {
"batch_index": 0,
"decimation": 1,
"discontinuity_threshold": 0.04,
"moge_geometry": [
"29:5",
0
],
"texture": True
},
"_meta": {
"title": "Convert MoGe Point Map to Mesh"
}
},
"29:30": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a > 2048",
"values.a": [
"29:31",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"29:31": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"28",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"29:33": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"28",
0
],
"on_true": [
"29:38",
0
],
"switch": [
"29:30",
2
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"29:34": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"28",
0
],
"on_true": [
"29:33",
0
],
"switch": False
},
"_meta": {
"title": "If/Else Switch"
}
},
"29:38": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"28",
0
],
"resize_type": "scale longer dimension",
"resize_type.longer_size": 2048,
"scale_method": "lanczos"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"29:5": {
"class_type": "MoGePanoramaInference",
"inputs": {
"batch_size": 4,
"image": [
"29:34",
0
],
"merge_resolution": 1024,
"moge_model": [
"29:8",
0
],
"refine_steps": 3,
"resolution_level": 5,
"split_resolution": 512
},
"_meta": {
"title": "Run MoGe Panorama Inference"
}
},
"29:8": {
"class_type": "LoadMoGeModel",
"inputs": {
"model_name": "moge_2_vitl_normal_fp16.safetensors"
},
"_meta": {
"title": "Load MoGe Model"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("28", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)