Edit a selected region
Use an image, mask, and instruction to replace only the selected area.
Descargar flujo de trabajoProbar en Cloud Documentación de la API
Dentro del flujo de trabajo
Una vista previa de solo lectura de la plantilla de origen. Ábrela en Cloud para explorar los nodos y hacer cambios.
Loading the graph
Open full-size workflow previewArchivos de este flujo de trabajo
- Autor
- ComfyUI
Llama a este modelo desde tu código
La solicitud a continuación utiliza el mismo grafo preparado y la misma configuración que el Playground. Cada envío puede iniciar una ejecución de pago; no reintentes automáticamente un envío cuyo resultado se desconozca.
1 Obtener clave de API ↗
What you need
- Runs on
- Comfy Cloud
- Clave
- COMFY_API_KEY
- Tus archivos
- El código los sube desde sus URL
Requiere un plan de pago de Cloud y créditos.
# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"47:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"47:23": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"47:34",
0
],
"text": "Change the blouse to a cream-colored, high-neck blouse with a soft scarf collar. Preserve the woman's face, hair, lighting, and wheat-field background."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"47:26": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"47:23",
0
],
"guidance": 30
},
"_meta": {
"title": "FluxGuidance"
}
},
"47:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"47:38",
2
],
"model": [
"47:39",
0
],
"negative": [
"47:38",
1
],
"positive": [
"47:38",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 190664687740330,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"47:31": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-fill-dev.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"47:32": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"47:34": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"47:38": {
"class_type": "InpaintModelConditioning",
"inputs": {
"mask": [
"workshop-mask",
0
],
"negative": [
"47:46",
0
],
"noise_mask": True,
"pixels": [
"17",
0
],
"positive": [
"47:26",
0
],
"vae": [
"47:32",
0
]
},
"_meta": {
"title": "InpaintModelConditioning"
}
},
"47:39": {
"class_type": "DifferentialDiffusion",
"inputs": {
"model": [
"47:31",
0
],
"strength": 1
},
"_meta": {
"title": "Differential Diffusion"
}
},
"47:46": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"47:23",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"47:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"47:3",
0
],
"vae": [
"47:32",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"workshop-mask": {
"class_type": "LoadImageMask",
"inputs": {
"channel": "alpha",
"image": "UPLOADED_mask_FILENAME"
},
"_meta": {
"title": "Edit mask"
}
}
})
workflow.set_input("17", "image", client.assets.from_url("https://cdn.jsdelivr.net/gh/Comfy-Org/workflow_templates@90c71fb78b3726392d010ff62a8e79e92d7296ad/input/flux_fill_inpaint_example_input_image.png"))
workflow.set_input("workshop-mask", "image", client.assets.from_url("https://cdn.jsdelivr.net/gh/Comfy-Org/workflow_templates@90c71fb78b3726392d010ff62a8e79e92d7296ad/input/flux_fill_inpaint_example_input_image.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("9"):
output.to_file(output.name)