0% found this document useful (0 votes)
13 views4 pages

ComfyScript Workflow Building Guide

Guia completo de ComfyScript para criar workflows de geração de imagens em Python integrados ao ComfyUI. Cobre fundamentos, padrões comuns de txt2img, loops, batch, condicionais, apps interativas e transpiler de workflows da GUI. Útil para devs que querem automatizar e escalar pipelines de IA visual.

Uploaded by

Marcelo Ribeiro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

ComfyScript Workflow Building Guide

Guia completo de ComfyScript para criar workflows de geração de imagens em Python integrados ao ComfyUI. Cobre fundamentos, padrões comuns de txt2img, loops, batch, condicionais, apps interativas e transpiler de workflows da GUI. Útil para devs que querem automatizar e escalar pipelines de IA visual.

Uploaded by

Marcelo Ribeiro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ComfyScript Complete Guide: Building Workflows

with Python
This comprehensive guide covers everything you need to know about building workflows,
interactive generators, and applications using ComfyScript and Python.

Overview of What You're Getting


The guide is organized into 11 major sections that take you from fundamental concepts through
advanced patterns:
Part 1-3: Foundation covers ComfyScript fundamentals, the two main execution modes (virtual
and real), and the basic structure of every script.
Part 4-5: Core Patterns walks through common workflow patterns including basic txt2img,
loops for prompt iteration, batch processing, conditionals, and two-pass workflows (base
generation + refinement). Each includes complete, runnable code examples.
Part 6-7: Practical Development shows how to retrieve and work with outputs, build interactive
applications (CLI, Jupyter, Gradio), and write reusable workflow functions. You'll learn how to
structure code for maximum reusability.
Part 8-10: Advanced Topics and Learning Path covers the transpiler (converting GUI workflows
to Python), common troubleshooting, and a structured 5-step learning path to get you
generating your first images quickly.

Key Concepts You'll Master

Understanding Node Functions


Every ComfyUI node becomes a Python function. The guide explains how inputs and outputs
map directly, and how to use type hints and enumerations for safer, clearer code. Instead of
guessing parameter names, you get IDE autocomplete after load() generates type stubs.

Three Execution Modes


Virtual Mode (most common): Your script runs through ComfyUI's queue system—perfect for
generating and saving images. Real Mode: Uses nodes as pure Python functions, ideal for
research and optimization. Workflow Generation: Creates .json workflows from Python code to
use in the GUI later.
Output Handling
The guide explains both methods: SaveImage() to disk (simplest), and util.get_images() to
retrieve PIL images in memory for further Python processing. This is crucial for interactive
applications and batch processing.

Reusable Architecture
You'll learn how to write helper functions that encapsulate common patterns (e.g.,
txt2img_pass(), create_conditioning()), making complex workflows maintainable and reducing
code duplication across projects.

Practical Examples Included


Dynamic Prompt Iteration: How to loop through multiple prompts, each with different seeds,
parameters, and output names—exactly what you mentioned needing in your original query.
Batch Processing: Load multiple images, process them, and save results—without manually
handling each file.
Conditional Logic: Enable/disable features, switch models, or adjust resolution based on a
single variable.
Two-Pass Workflows: Base generation at low resolution, then upscale and refine—the hires-fix
pattern.
Interactive Apps: From simple CLI input to full Gradio web interfaces with sliders and text inputs.

The Learning Path


The guide includes a structured 5-step learning path at the end:
1. Run a Basic Script — Generate a single image to verify everything works
2. Add a Loop — Generate multiple variations of one concept
3. Retrieve Images In-Memory — Work with PIL objects instead of just saving
4. Transpile an Existing Workflow — Learn from workflows you've already built in the GUI
5. Experiment with Parameters — Wrap logic in functions and try different values

What Makes This Different


Rather than just showing syntax, the guide emphasizes structure and patterns. You'll
understand not just how to call a node, but why you structure workflows certain ways, how to
avoid common mistakes (like forgetting load()), and how to think programmatically about image
generation tasks.
The document is designed to be referenced continuously—when you're stuck on prompt
iteration, flip to Part 4.2. When you want to build an interactive app, go to Part 6. Each section is
self-contained but builds on earlier concepts.

Ready to Use This


You now have a complete reference guide covering installation context (from our previous
session), core concepts, practical patterns, common issues, and a clear learning path. Start with
Step 1 in Part 10, then move through the examples at your own pace. As you build more complex
workflows, the advanced patterns in Part 7 and the troubleshooting in Part 9 will guide you
through challenges.
The document is saved and ready to reference as you start writing your first ComfyScript
workflows.

1. [Link]
2. [Link]
3. [Link]
4. [Link]
5. [Link]
6. [Link]
7. [Link] [Link]
8. [Link]
9. [Link]
10. [Link]
11. [Link]
12. [Link]
13. [Link]
-folder
14. [Link]
15. [Link]
returning-more-than-just-an-im
16. [Link]
17. [Link]
18. [Link]
19. [Link]
20. [Link]
21. [Link]
22. [Link]
23. [Link]
24. [Link]
25. [Link]
26. [Link]
27. [Link]
28. [Link] whileLoopStart

Common questions

Powered by AI

The guide recommends building interactive applications using tools like CLI, Jupyter, and Gradio. These tools enable the creation of simple to complex interfaces, such as full Gradio web interfaces with sliders and text inputs, to accommodate user interaction and dynamic adjustments within applications .

The ComfyScript guide suggests handling multiple text prompts by utilizing dynamic prompt iteration, where each prompt can have different seeds, parameters, and output names. This is supported by coding patterns that allow looping through multiple prompts with individual configurations .

The two execution modes in the ComfyScript guide are Virtual Mode and Real Mode. Virtual Mode is preferred for tasks like generating and saving images through ComfyUI's queue system, offering a streamlined approach for batch tasks. Real Mode is preferable for research and optimization purposes where nodes are used as pure Python functions, allowing for detailed analysis and refinement .

The learning path facilitates progressive learning by sequentially building on previous concepts and increasing complexity. Key steps include running a basic script, adding loops for generating multiple variations, retrieving images in-memory, transpiling existing workflows from the GUI, and experimenting with different parameters .

The guide differentiates between direct image saving using SaveImage() to disk, which is the simplest method, and in-memory image retrieval using util.get_images(), which allows for further processing with PIL in Python. This in-memory approach is crucial for interactive applications that require immediate access to image data .

Virtual mode execution in ComfyScript significantly benefits image generation tasks by leveraging ComfyUI's queue system, which handles automated task management and efficient batch processing. Its advantages include streamlined workflow execution, reduced manual intervention, and the ability to manage outputs systematically compared to more intricately controlled real mode execution .

Type hinting and IDE autocompletion improve workflow generation by ensuring safer and clearer code. When load() generates type stubs, the guide emphasizes how this allows developers to avoid guessing parameter names, simplifying development and reducing errors through predictive coding support .

The guide recommends structuring code by creating reusable workflow functions that encapsulate common patterns. This involves writing helper functions to manage operations like txt2img_pass() and create_conditioning(), thus ensuring that complex workflows remain maintainable and reducing code duplication across projects .

The guide provides guidance on implementing two-pass workflows by first performing a base generation at low resolution, followed by an upscale and refinement step. One potential application of this pattern is the hires-fix process, where initial images are quickly generated and then refined for higher quality output .

The ComfyScript guide addresses batch processing by allowing users to load multiple images, process them simultaneously, and save the results without manually handling each file individually. This is achieved through workflow generation that supports efficient automation and repetition of tasks .

You might also like