Separate an image into editable layers
Decompose an image into transparent layers for further editing and compositing.
下载工作流在 Cloud 中试用 API 文档
查看工作流内部
源模板的只读预览。在 Cloud 中打开,即可查看节点并进行修改。
Loading the graph
Open full-size workflow preview- 作者
- ComfyUI
从代码中调用该模型
以下请求使用与体验区相同的预设图和设置。每次提交都可能开始一次付费运行;如果提交结果未知,请勿自动重试。
1 获取 API 密钥 ↗
What you need
- Runs on
- Comfy Cloud
- 密钥
- COMFY_API_KEY
- 你的文件
- 由代码根据链接上传
需要付费的 Cloud 方案和额度。
# 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({
"60": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Qwen-image-layers",
"images": [
"83:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"74": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"82": {
"class_type": "ImageScaleToMaxDimension",
"inputs": {
"image": [
"74",
0
],
"largest_size": 640,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Max Dimension"
}
},
"116": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "A cinematic medium shot of a beautiful young woman with fair skin and a joyful, radiant smile, looking back over her shoulder. She has voluminous, curly auburn hair styled in a loose, windblown updo. She is standing on a rugged, rocky coastline overlooking a sun-drenched ocean. She wears a vintage, long-sleeved, high-collared dress in an off-white, crinkled fabric with delicate smocking on the bodice and a simple brown sash at her waist. In the background, the ocean sparkles brightly under the sun, and a majestic tall ship with full sails is visible in the distance. The scene is illuminated by the warm, golden light of the late afternoon, creating a soft, romantic, and nostalgic atmosphere with a shallow depth of field that keeps the woman in sharp focus."
},
"_meta": {
"title": "Prompt"
}
},
"83:118": {
"class_type": "EmptyQwenImageLayeredLatentImage",
"inputs": {
"batch_size": 1,
"height": [
"83:78",
1
],
"layers": 2,
"width": [
"83:78",
0
]
},
"_meta": {
"title": "Empty Qwen Image Layered Latent"
}
},
"83:140": {
"class_type": "LatentCut",
"inputs": {
"amount": 16384,
"dim": "t",
"index": 1,
"samples": [
"83:3",
0
]
},
"_meta": {
"title": "LatentCut"
}
},
"83:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 2.5,
"denoise": 1,
"latent_image": [
"83:118",
0
],
"model": [
"83:66",
0
],
"negative": [
"83:70",
0
],
"positive": [
"83:69",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 331728509923362,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"83:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_layered_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"83:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"83:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_layered_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"83:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"83:38",
0
],
"text": [
"116",
0
]
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"83:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"83:37",
0
],
"sampling": "flow",
"shift": 1
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"83:69": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"83:6",
0
],
"latent": [
"83:71",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"83:7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"83:38",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"83:70": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"83:7",
0
],
"latent": [
"83:71",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"83:71": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"82",
0
],
"vae": [
"83:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"83:76": {
"class_type": "LatentCutToBatch",
"inputs": {
"dim": "t",
"samples": [
"83:140",
0
],
"slice_size": 1
},
"_meta": {
"title": "LatentCutToBatch"
}
},
"83:78": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"82",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"83:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"83:76",
0
],
"vae": [
"83:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
workflow.set_input("74", "image", client.assets.from_url("https://cdn.jsdelivr.net/gh/Comfy-Org/workflow_templates@90c71fb78b3726392d010ff62a8e79e92d7296ad/input/coastal_smiling_woman.png"))
# 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("60"):
output.to_file(output.name)