Introduction
After releasing my first wildcards yesterday, I realized, that they got pretty much clicks in a short time. So I guess wildcards are a topic for itself.
How to create Wildcards
There's already a really nice guide on how to create wildcards with GPT. That's what I used, too, to create my wildcard lists. Link to arcticle
How to use Wildcards
To use wildcards you need the Dynamic Prompts Extension. It can do even more then just using wildcards. Put the wildcards in the wildcard folder of your Dynamic Prompts extension. it is ususlly located in
stable-diffusion-webui\extensions\sd-dynamic-prompts
Use the filename with 2 underscores in front and in the back __filename__ in your prompts.
Keep in mind, that those are only wildcards. Your model might not have learned all of the items.
A useful tool to manage your wildcards is the Wildcard Manager that comes with Dynamic Prompts.
How to make them wilder?
Method 1 - wild
Well that's pretty simple... You can create wildcards which use wildcards.
E.g.: You have one wildcard containing colors, like red, blue, green and so on. Let's assume its simply named: "colors.txt".
You have another wildcard with clothings, like T-Shirt, bra, top, pullover and so on, named "clothings.txt"
Now just create a simple new textfile name it for example: "clothing_colored.txt" and use the two other wildcards as file content:
__color__ __clothing__
Like this, you can get combinations of all the colors and clothings.
Method 2 - wilder
Dynamic Prompts Syntax, you can find a full guide here.
Combinations
Choose a number of terms from a list, in this case we choose two artists: {2$$artist1|artist2|artist3}
If $$ is not provided, then 1$$ is assumed.
If the chosen number of terms is greater than the available terms, then some terms will be duplicated, otherwise chosen terms will be unique. This is useful in the case of wildcards, e.g. {2$$__artist__}
is equivalent to {2$$__artist__|__artist__}
A range can be provided: {1-3$$artist1|artist2|artist3}
In this case, a random number of artists between 1 and 3 is chosen.
Options can be given weights: {2::artist1|artist2}
In this case, artist1 will be chosen twice as often as artist2.
Wildcards can be used and the joiner can also be specified: {{1-$$and$$__adjective__}}
Here, a random number between 1 and 3 words from adjective.txt will be chosen and joined together with the word 'and' instead of the default comma.
Variables
Set a variable like so: ${season=!{summer|autumn|winter|spring}}
Now use it like this: In ${season} I wear a ${season} shirt and ${season} trousers
For more details, and functionality, see the documentation.
Method 3 - even wilder - prompt editing
Further you can include prompt editing to your wildcards, examples are taken from A1111-GIT.
from-to-when:
when is the percentage of steps used for generation
you can skip "from" or "when"
[from:to:when]
[mountain:lake:0.25]
[lake:0.25] #from skipped
[mountain::0.25] #to skipped
alternating words
the example will switch with each step betwenn cow and horse and blend them together
you can add more items to it
[cow|horse]
[cow|horse|man]
How to make them better and easy to maintain
After creating my first large set of wildcards using single files for each item, I got frustrated a bit, because I needed to change things recursivly.
After reading the Dynamic Prompts Syntax sheet cheat. It mentions the possibility to use YAML-Files, structured textfiles. This gives you the power to use a single file for all of your wildcards.
I suggest using Notepad++ it let's you collapse sections of you wildcard so you're not flouded with all of your items.
Structure
You create a main topic, like clothing.
In the next line you use indentation for the subcategory.
In the next line you might want to put your items of another subcategory maybe?
Best shown in an example
# BoCharsMag.yaml
clothings-magical:
female:
upper-body:
- T-Shirt
- Pullover
full-body:
- robe
- gown
male:
footwear:
- shoes
- boots
headwear:
- hat
- crown
next-main-category:
Important:
Categorys have an ":" at the end of the line.
Items start with "- "
don't use Tabs
the space behind the "-" is important, too
If you use Dynamic Prompts build-in syntax with the "{ }" use quotes around them
Usage:
They can be used like other wildcards, however, you have to include the structure:
__clothings-magical/female/upper-body__
Creating an index
Notepad++ gives you an easy way to create an index of your wildcards. Simply bookmark your category lines. ;)
If you already have a long YAML-file you can use the Find function and use the "Mark"-tab to create bookmarks in lines with "- " and invert them afterwards with Menu->Search->Boomark->Inverse Bookmark.
Better: enable "Regular Expression" and use this regex:
(?<![:{]):\n
or
(?<![:{]):\r
depending on text encoding
It scans for : not preceded by { or :
Examples
and many more
There are already wildcards using those methods, but I didn't find an article describing it.