For loops
CushyApps supports any kind of control flow. This page show how to do so
Last updated
CushyApps supports any kind of control flow. This page show how to do so
Last updated
Key learnings:
Start from the default app, and enhance it to allow for a configurable number of recursive samplers.
Add a new number input to control how many ksampler we want
Use that number to genearte
app({
model: form.enum['CheckpointLoaderSimple.ckpt_name']({}),
positive: form.string({ default: 'masterpiece, tree' }),
seed: form.seed({}),
+ // 1. add new UI control to display how many loops you want
+ loops: form.number({ default: 3 }),
}),
run: async (run, ui) => {
const workflow = run.workflow
const graph = workflow.builder
const ckpt = graph.CheckpointLoaderSimple({ ckpt_name: ui.model })
+ // 2. here, I'm using the _LATENT annotation to allow to assign any node
+ // that produce a latent, and not just an EmptyLatentImage node.
let latent: Comfy.Signal['LATENT'] = graph.EmptyLatentImage({})
+ // 3. moving embeddigns node definition outside of the Ksampler,
+ // as variable, so they can be used in the loop below
+ const pos = graph.CLIPTextEncode({ clip: ckpt, text: ui.positive })
+ const neg = graph.CLIPTextEncode({ clip: ckpt, text: '' })
latent = graph.KSampler({
seed: ui.seed,
latent_image: latent,
model: ckpt,
sampler_name: 'ddim',
scheduler: 'karras',
- positive: graph.CLIPTextEncode({ clip: ckpt, text: ui.positive }),
- negative: graph.CLIPTextEncode({ clip: ckpt, text: '' }),
+ positive: pos, // use the variables
+ negative: neg, // use the variables
})
+
+ // 4. add a for loop
+ for (let i = 0; i < ui.loops; i++) {
+ // 👇 I'm reassigning latent variable
+ latent = graph.KSampler({
+ seed: ui.seed,
+ latent_image: latent, // 👈 from the previous latent
+ model: ckpt,
+ sampler_name: 'ddim',
+ scheduler: 'karras',
+ positive: pos,
+ negative: neg,
+ })
+ }
+
const image = graph.VAEDecode({
samples: latent,
vae: ckpt,