Flux Kontext Dev 圖像編輯
使用Flux Kontext全節點可見性編輯圖像,非常適合學習工作流程。
下載工作流程在 Cloud 中試用 API 文件
工作流程內部
來源範本的唯讀預覽。請在 Cloud 中開啟,以探索節點並進行變更。
Loading the graph
Open full-size workflow preview從您的程式碼呼叫此模型
以下請求使用與 Playground 相同的已準備節點圖和設定。每次提交都可能啟動付費執行;若提交結果不明,請勿自動重試提交。
1 取得 API 金鑰 ↗
What you need
- Runs on
- Comfy Cloud
- 金鑰
- COMFY_API_KEY
- 您的檔案
- 由程式碼透過其 URL 上傳
需要付費 Cloud 方案與點數。
下載 API JSONAPI 文件 ↗
# 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({
"136": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"192:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"190": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"192:124": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"192:42",
0
],
"vae": [
"192:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"192:135": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"192:6",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"192:146": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"190",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
},
"192:177": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"192:6",
0
],
"latent": [
"192:124",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"192:31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"192:124",
0
],
"model": [
"192:37",
0
],
"negative": [
"192:135",
0
],
"positive": [
"192:35",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 784381637916598,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"192:35": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"192:177",
0
],
"guidance": 2.5
},
"_meta": {
"title": "FluxGuidance"
}
},
"192:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-dev-kontext_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"192:38": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"192:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"192:42": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"192:146",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"192:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"192:38",
0
],
"text": "Change the season and the time of day while keeping the woodcarver, his pose, the workbench and the whole layout of the workshop exactly as they are. It is now a snowy winter evening: deep blue dusk outside the tall windows, snow piled on the window ledges and falling softly beyond the glass. Inside, warm amber light from a few hanging pendant lamps and a glowing cast-iron stove in the corner replaces the cold daylight, casting soft orange highlights on the wood shavings, the timber racks and the carver's hands and face. Keep the same camera angle, the same documentary photographic style, the same textures of wood, denim and steel, and do not add any people, lettering or signs."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"192:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"192:31",
0
],
"vae": [
"192:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
workflow.set_input("190", "image", client.assets.from_url("https://comfy.org/catalog-media/86baffb0-590c-4284-a5e1-70bfcee63197/48e4a7e1-d791-4d4a-a8f4-3c4bf47a393f"))
# 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("136"):
output.to_file(output.name)試試範例
關於此工作流程
「Flux Kontext Dev 圖像編輯」工作流程專為需要角色一致性與局部編輯的進階圖像處理而設計。此流程運用 Flux.1 Kontext 模型,能理解並保留原始圖像風格,同時精確修改指定區域。流程包含 SaveImage、MarkdownNote、LoadImage 及自訂節點(以唯一 ID 標示),提供針對性圖像變更的完整架構。技術上,流程會先載入影像,透過 diffusion 模型 'flux1-dev-kontext_fp8_scaled.safetensors' 進行指定編輯,最後儲存已編輯影像,確保原始風格與角色細節完整保留。特別適合需維持視覺一致性的應用,如遊戲或動畫角色設計。
問答
可以,你可在提示詞中指定多項編輯,流程會同時套用並維持一致性與風格。
最適合需維持角色一致性與風格的影像,如人像或風格化藝術圖。
Flux.1 Kontext 模型能理解並複製原始風格,確保編輯不會破壞整體美感。
你可重新載入原始影像並調整提示詞,反覆優化直到達到理想效果。