Sign In

How to create wilder Wildcards and some prompt editing

How to create wilder Wildcards and some prompt editing

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:

Errors:

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

There are many simple errors you can make while creating wildcards.

  • it is important that you test you wildcards

  • usual syntax errors:

  • missing - in front of items

scenes:
    dark:
        items  # ERROR
  • missing _ when nesting wildcards

dress-properties-scifi:
        - __random/color_  # ERROR
  • unclosed brackets

dress-properties-scifi:
        - "{1-3$$  $$__random/color__|__properties/fabric-scifi__|__properties/patterns/clothing-scifi__"  # ERROR
  • if your prompts start with a { bracket, you have to use quotes or use the option a bit farther below

  • the error for those 3 will look like this in cmd:

Error running process: stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py,  3.22it/s]
Traceback (most recent call last):
  File "\stable-diffusion-webui\modules\scripts.py", line 451, in process
    script.process(p, *script_args)
  File "stable-diffusion-webui\extensions\sd-dynamic-prompts\sd_dynamic_prompts\dynamic_prompting.py", line 482, in process
    all_prompts, all_negative_prompts = generate_prompts(
  File "\stable-diffusion-webui\extensions\sd-dynamic-prompts\sd_dynamic_prompts\helpers.py", line 93, in generate_prompts
    all_prompts = prompt_generator.generate(prompt, num_prompts, seeds=seeds) or [""]
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\generators\randomprompt.py", line 71, in generate
    prompts.append(next(iter(gen)))
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\samplers\base.py", line 75, in _get_sequence
    yield rotate_and_join(sub_generators, separator=command.separator)
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\utils.py", line 43, in rotate_and_join
    return separator.join(rotate_all(generators))
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\utils.py", line 35, in rotate_all
    return [next(gen) for gen in generators]
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\utils.py", line 35, in <listcomp>
    return [next(gen) for gen in generators]
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\samplers\random.py", line 118, in _get_wildcard
    yield from context.sample_prompts(value, 1)
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\sampling_context.py", line 119, in sample_prompts
    command = parse(prompt, parser_config=self.parser_config)
  File "\stable-diffusion-webui\venv\lib\site-packages\dynamicprompts\parser\parse.py", line 454, in parse
    tokens = get_cached_parser(parser_config).parse_string(
  File "\stable-diffusion-webui\venv\lib\site-packages\pyparsing\core.py", line 1141, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found '_'  (at char 35), (line:1, col:36)
  • prompt starting with "- {" or long multilined prompts

  • best practise for SD so far:

category:
    - >-
      {...content...
      ...
      ...}
    - >-
      ...
      ...
      ...
  • if a nested wildcard is not found, you get a message in the SD command window

    • example, I wrote buildings-scfi with a missing "i" in my wildcards

No values found for wildcard random/buildings-scifi

random:
    buildings-scfi

Resources:

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

or just
:$

It scans for : not preceded by { or :

Examples

Billions of characters

Full Feature Character

and many more

There are already wildcards using those methods, but I didn't find an article describing it.

176

Comments