Capstone: Advanced Workflow from Concept to Output
- Assemble a four-stage ComfyUI graph: base generation with LoRA, Kontext scene editing, FLUX Fill correction, and Ultimate SD Upscale
- Wire the stages so each stage output connects directly to the next stage input, with the character LoRA applied consistently through all KSampler nodes
- Export the assembled workflow in API format and write a Python script that accepts a character prompt and scene edit instruction as inputs
- Apply the VRAM optimisations from Lesson 11 to fit the full four-stage pipeline onto a 16-24 GB GPU
What You Are Building
This capstone builds a complete production workflow for a character-driven image series: a consistent character placed in multiple scenes with controlled edits. You will combine the five main techniques from this track into a single end-to-end pipeline, then automate it via the ComfyUI API.
The workflow has four stages:
- Base generation: FLUX.1 dev + a trained character LoRA produces a clean initial image of the character
- Scene editing: FLUX Kontext edits the scene while preserving the character's identity
- Detail refinement: FLUX Fill corrects any element in the scene (background objects, clothing details, lighting artefacts)
- Final upscale: Ultimate SD Upscale tiles the composition to 4× the base resolution for print or large-screen delivery
By the end of this lesson you will have exported the full pipeline in API format and written a Python script that accepts a character prompt and scene description as inputs and delivers a full-resolution output image.
Stage 1: Base Character Generation
Start with a standard FLUX.1 dev workflow with a character LoRA loaded at strength 0.8. Use FP8 for the diffusion model and text encoders unless you have 48 GB VRAM to spare — the rest of the pipeline adds more models and you need headroom for stages 2 and 3.
Base generation settings:
- Resolution: 1024×1024 (FLUX's native resolution; upscaling happens in stage 4)
- Steps: 25 with Euler sampler, simple scheduler
- CFG: 1.0 (FLUX ignores the negative prompt and runs guidance-free; CFG values above 1 do not behave as they do in SDXL)
- LoRA strength: 0.8 for the character LoRA
Write the character prompt carefully. Include the trigger word at the start, then describe the specific scene you want for this base image: lighting, angle, clothing, expression. This is the reference image that Kontext will edit in stage 2 — a clean, well-lit image with a neutral background makes editing more reliable.
Save the best output from this stage. You will use it as the input image for stage 2.
Stage 2: Scene Editing with FLUX Kontext
Load the FLUX Kontext Dev workflow from Workflow → Browse Templates → Flux → FLUX Kontext Dev Image Edit. Connect your base image as the input.
Keep the character LoRA loaded at reduced strength (0.6) during Kontext editing. Without the LoRA, Kontext edits may drift slightly from the character's appearance, especially in novel scenes.
Write editing instructions using the patterns from Lesson 1:
- Scene replacement: "Change the background to a rain-soaked city street at night, keeping the character exactly as they are"
- Lighting change: "Change the lighting to warm golden-hour sunlight coming from the left"
- Clothing edit: "Replace the jacket with a dark navy peacoat, keeping everything else the same"
Run several editing variations on the base image. The Kontext iterative loop — where you use the previous output as the next input — works well for accumulating multiple small changes, but be aware that each iteration slightly degrades fine detail. Keep iterative chains short (2–3 edits maximum for a single delivery image).
Select the best Kontext output. This is your composition for stage 3.
Stage 3: Detail Refinement with FLUX Fill
Inspect your Kontext output for elements that need correction: a background object that looks wrong, a lighting inconsistency, a clothing seam that the edit did not handle cleanly.
Add the FLUX Fill model (flux1-fill-dev.safetensors) to your workflow. Right-click a Load Image node and select Open in MaskEditor to paint a mask over the area to fix. Run FLUX Fill with:
- Denoise strength: 0.6–0.8 for significant changes; 0.3–0.5 for minor corrections
- Steps: 25 (same as base generation)
- The character LoRA still loaded at 0.5–0.6 — this helps keep the character consistent even when filling areas near them
FLUX Fill can fix errors in the composition that would be difficult to correct with Kontext alone. Use it selectively — over-correcting with Fill can flatten the image and reduce the coherence Kontext established.
If the composition looks clean without corrections, skip stage 3 entirely. Not every image needs a Fill pass.
Stage 4: Upscaling to Final Resolution
Once the composition is complete, upscale it to final delivery resolution using the Ultimate SD Upscale pipeline from Lesson 4:
- Run the image through the ESRGAN 4× upscaler node to reach roughly 4096×4096 from a 1024×1024 base
- Pass the result to Ultimate SD Upscale with denoise 0.3, tile size 1024, Chess mode, 32px padding, Half Tile seam fix
Use FP8 or GGUF quantization for the diffusion model in this stage — the upscaler does not need BF16 quality, and the VRAM freed up by quantization is needed to hold the large intermediate image tensor.
If you are on a 16 GB GPU and the upscale step runs out of VRAM, replace the standard VAE Decode node with VAE Decode (Tiled) at tile_size 512, overlap 64. This decodes the final image in tiles and resolves OOM errors at resolutions above 2048px.
Assembling the Full ComfyUI Graph
All four stages can be built as a single ComfyUI graph — each stage's output connects to the next stage's input node. The resulting graph is large (60–80 nodes) but manageable with ComfyUI's group feature: select the nodes for each stage, right-click, and select Group Nodes to collapse them into a labelled group.
Important connection points:
- Stage 1 → Stage 2: wire the Save Image output from stage 1 to a Load Image node at the start of stage 2 — or, more cleanly, wire the VAE-decoded IMAGE output directly to the Kontext image input, bypassing the save/load cycle
- Stage 2 → Stage 3: same pattern — wire the Kontext output IMAGE directly to the FLUX Fill Load Image node
- Stage 3 → Stage 4: wire the Fill output IMAGE to the ESRGAN upscale node's image input
Keep the LoRA loaded at the top of the graph and pass its model output through all stages. Each stage's KSampler or FluxKontextSampler connects to the LoRA model output, not directly to the Load Diffusion Model output. This ensures the LoRA is applied consistently through every generation step.
Exporting and Automating the Pipeline
Once the full graph is working correctly on a test image, export it in API format: Settings → Developer → Dev Mode Options → Save (API Format) → save as character_pipeline_api.json.
Identify the node IDs for the two inputs you want to control from the Python API:
- The positive CLIPTextEncode node for the base generation prompt (stage 1)
- The CLIPTextEncode node used for the Kontext edit instruction (stage 2)
Write a Python script using the pattern from Lesson 9:
import json, random
from pathlib import Path
# Load once at startup
with open("character_pipeline_api.json") as f:
BASE_WORKFLOW = json.load(f)
def generate_scene(character_prompt: str, scene_edit: str) -> bytes:
workflow = json.loads(json.dumps(BASE_WORKFLOW))
workflow["6"]["inputs"]["text"] = character_prompt # stage 1 prompt node
workflow["42"]["inputs"]["text"] = scene_edit # stage 2 Kontext edit node
workflow["3"]["inputs"]["seed"] = random.randint(0, 2**32)
# queue and wait using the full script from Lesson 9
return queue_and_wait(workflow)
scenes = [
("zrn1char, standing on a rooftop", "Change the background to a rain-soaked city at night"),
("zrn1char, in a coffee shop", "Move the character to a sunlit garden terrace"),
]
for char_prompt, scene_desc in scenes:
img_bytes = generate_scene(char_prompt, scene_desc)
slug = "_".join(scene_desc[:20].split())
Path("output_" + slug + ".png").write_bytes(img_bytes)
This script generates a full 4-stage pipeline output for each scene description — base generation, Kontext edit, Fill correction (if the mask node is wired into the graph), and final upscale — all from a single function call per scene.
What You Have Built Across This Track
This capstone ties together every technique covered in the track:
- Lessons 1–2: FLUX Kontext for instruction-based editing and character consistency across scenes
- Lesson 3: FLUX Fill for context-aware inpainting and FLUX Depth for structure-guided generation
- Lesson 4: Ultimate SD Upscale for tiled high-resolution output beyond ComfyUI's native resolution limits
- Lesson 5: Regional prompting for controlling different areas of a composition independently
- Lessons 6–8: LoRA training from dataset preparation through Kohya training to testing and fixing — the trained LoRA is the character anchor in this capstone workflow
- Lessons 9–10: The ComfyUI API and production pipeline — the Python automation that runs the full workflow from a script call
- Lesson 11: VRAM and performance optimisation — FP8/GGUF to fit all four stages onto a 16–24 GB GPU
The techniques in this track are not specific to character workflows. The same combination — a LoRA for identity, Kontext for scene flexibility, Fill for corrections, Ultimate Upscale for delivery — applies to product photography, architectural visualisation, and any workflow where consistent visual identity across varied contexts is the goal.
- All four stages can be wired as a single ComfyUI graph — keep the character LoRA loaded at the top and pass its model output through every stage so the character anchor applies consistently
- Kontext iterative chains should stay at 2-3 edits maximum — each pass slightly degrades fine detail, and long chains drift from the original composition
- FLUX CFG is 1.0 and guidance-free — CFG values above 1.0 do not behave like SDXL; the negative prompt has no effect in FLUX workflows
- Stage 3 (FLUX Fill) is optional — only use it when the Kontext output has specific areas that need correction; over-correcting with Fill reduces the coherence Kontext established
- The API automation pattern is the same regardless of pipeline complexity: deep-copy the workflow, modify the target node inputs, queue it — the graph handles all four stages in a single API call
Progress is saved in this browser only — clear your cache or switch device and it's gone. Create a free account and it follows you everywhere.