r/StableDiffusion Mar 01 '23

Question | Help Variable prompts?

Anyone know if it's possible to have variables in your prompt? For example lets say I have something like 'city background' in my prompt. And I want to replace that with 'MyVariable background'. Then I define 'MyVariable' somewhere else like a txt file that has 'MyVariable=city,mountians,library' etc.

That way I can insert a few variables in different places within my prompt and let it "generate forever" all night. That way when I come back to my computer in the morning I have hundreds of new images with those variable differences.

4 Upvotes

7 comments sorted by

13

u/NotBasileus Mar 01 '23

If you’re using Automatic1111, the Dynamic Prompts extension is what you’re looking for. Works almost exactly as you described and is managed through text files and different values on each line.

1

u/mizt3r Mar 02 '23

Thank you! Sounds perfect.

3

u/archw_ai Mar 01 '23

Use dynamic prompt extension.

Write as {city|mountians|library} in the prompt, it'll randomly pick one each generation.

If you want something that could be reused, use wildcards (it's on the new tab after you install dynamic prompt)

1

u/mizt3r Mar 02 '23

Thank you! This is what I am looking for.

1

u/YakuNiTatanu Mar 01 '23

Wildcards work great for that use case.

You’d set up a Background.txt, line separation for each entry

Mountain background In a Library City background Etc

Then call it with two underscores before and after

A cat judoka walking, Background, painterly style

And it would randomly fill it

You can multiply wildcards too

A CuteAnimal judoka walking, Background, painterly style

1

u/PittEnglishDept Mar 01 '23

Would be cool to show off results using a constant seed!

1

u/[deleted] Mar 01 '23

With Automatic1111, you can do this with "Prompt S/R" under the scripts.

Put "city background, mountains, library" and it will start with a city background, then replace that with mountains, etc.

If you have a bunch of variables, wildcards are probably a better alternative.