Two versions of a prompt with one switch
Lesson "switch", in the group Packs and tools of the lesson list. Steps: 9.
What you will be able to do
You keep two prompts in one graph and choose between them with one yes/no value, the way ComfyUI's templates do.
What you need
- It goes on from A first picture from text. The card says so; it is a hint, not a lock.
- Nodes: CLIP Text Encode (Prompt), KSampler, Text (Multiline), If/Else Switch, Boolean.
- The app downloads and installs nothing. The step texts below say which files and folders, and which ComfyUI template names them.
The steps
The words of each step, as the lesson shows them. Node names are in bold.
Compare without rewiring (reading)
To compare two prompts you would retype the text or move links each time. ComfyUI's templates do it with a switch: both versions stay in the graph, and one yes/no value chooses which one goes on.
This lesson builds that on the graph of "A first picture from text". The same switch later chooses between your prompt and one a language model rewrote.
The picture graph is needed
The canvas must have the graph of "A first picture from text": the CLIP Text Encode (Prompt) node whose output goes into the
positiveinput of KSampler.If it is not there, do that lesson first.
The first version
Add a Text (Multiline) node and write a prompt into its
valuefield. For example: a lighthouse on a cliff at sunset, warm light, calm sea.This node holds the text in one visible place. It goes on to the switch, not straight into CLIP Text Encode (Prompt).
The second version
Add a second Text (Multiline) node and write another version into its
valuefield: the same subject in another light, another style or with one more detail.Change one thing only. Then you see what that one change did.
The switch
Add a If/Else Switch node. Connect the output of Text (Multiline) to its
on_falseinput and the output of Text (Multiline) to itson_trueinput.The switch passes on one of the two. Only the chosen side is worked out.
Into the prompt
Connect the
outputof If/Else Switch to thetextinput of CLIP Text Encode (Prompt).The
textfield of CLIP Text Encode (Prompt) now takes its words from the link, and the text typed in it is no longer used. The rest of the graph stays as it was.The yes/no value
Add a Boolean node, connect its output to the
switchinput of If/Else Switch and set itsvaluetotrue.truechooseson_true, the second version;falsechooseson_false, the first. The choice now sits in one small node you can find at once.How to compare (reading)
In ComfyUI set
control_after_generateunder theseedof KSampler tofixed. Run once withtrueand once withfalse.With the same
seedthe two pictures differ only by the prompt. If they also differed by the noise, you could not tell which change did what.The graph is ready (reading)
Save the graph with "File ▸ Save workflow for ComfyUI…", open the file in ComfyUI and run it there. This app runs nothing in ComfyUI itself.
The same switch works for anything of one type: two models, two LoRA settings, two sizes. Both sides must carry the same type.
Next: "A language model writes the prompt" puts a language model on the
on_trueside.
What the lesson checks
A reading step is done when you press Got it, next. A doing step ticks itself off when the canvas holds:
- Step 2, The picture graph is needed:
- a CLIP Text Encode (Prompt) node.
- a KSampler node.
CONDITIONINGof CLIP Text Encode (Prompt) intopositiveof KSampler.
- Step 3, The first version:
- a Text (Multiline) node.
valueof Text (Multiline) (first version) holds at least 10 characters.
- Step 4, The second version:
- a Text (Multiline) node.
valueof Text (Multiline) (second version) is not the same file asvalueof Text (Multiline) (first version).
- Step 5, The switch:
- a If/Else Switch node.
STRINGof Text (Multiline) (first version) intoon_falseof If/Else Switch.STRINGof Text (Multiline) (second version) intoon_trueof If/Else Switch.
- Step 6, Into the prompt:
outputof If/Else Switch intotextof CLIP Text Encode (Prompt).
- Step 7, The yes/no value:
- a Boolean node.
BOOLEANof Boolean intoswitchof If/Else Switch.valueof Boolean istrue.
What next
These lessons go on from this one: A language model writes the prompt.