Skip to content

Commit

Permalink
* New parser, which now supports the attention, alternation and sched…
Browse files Browse the repository at this point in the history
…uling modifiers and replicates them in the negative prompt when necessary. Implements issue #1.

* Removed configuration of tag format since it cannot be done with the new parser.
  • Loading branch information
acorderob committed Aug 13, 2023
1 parent 7f36587 commit c8a7b6c
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 142 deletions.
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,34 @@ that part to the negative prompt.

## Configuration

The extension settings allow you to change the format of the tag in case there
is some incompatibility with another extension.
Separator used when adding to the negative prompt: You can specify the separator used when adding to the negative prompt (by default it's ", ").

You can also specify the separator added to the negative prompt which by
default is ", ".
Ignore tags with repeated content: by default it ignores repeated content to avoid repetitions in the negative prompt.

By default it ignores repeated content and also tries to clean up the prompt
after removing the tags, but these can also be changed in the settings.
Join attention modifiers (weights) when possible: by default it joins attention modifiers when possible (joins into one, multipliying their values).

Try to clean-up the prompt after processing: by default cleans up the positive prompt after processing, removing extra spaces and separators.

## Notes

The content of the negative tags is not processed and is copied as is to the negative prompt. Other modifiers around the tags are processed in the following way.

### Attention modifiers (weights)

They will be translated to the negative prompt. For example:

* `(red<!square!>:1.5)` will end up as `(square:1.5)` in the negative prompt
* `(red[<!square!>]:1.5)` will end up as `(square:1.35)` in the negative prompt (weight=1.5*0.9)
* However `(red<![square]!>:1.5)` will end up as `([square]:1.5)` in the negative prompt. The content of the negative tag is copied as is, and not joined with the surrounding modifier.

### Prompt editing constructs (alternation and scheduling)

Negative tags inside such constructs will copy the construct to the negative prompt, but separating its elements. For example:

* Alternation: `[red<!square!>|blue<!circle!>]` will end up as `[square|], [|circle]` in the negative prompt, instead of `[square|circle]`
* Scheduling: `[red<!square!>:blue<!circle!>:0.5]` will end up as `[square::0.5], [:circle:0.5]` instead of `[square:circle:0.5]`

This should still work as intended, and the only negative point i see is the unnecessary separators.

## License

Expand Down
40 changes: 8 additions & 32 deletions scripts/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,6 @@ def process(self, p: StableDiffusionProcessing, *args, **kwargs):

def __on_ui_settings(self):
section = ("send-to-negative", SendToNegative.NAME)
shared.opts.add_option(
key="stn_tagstart",
info=shared.OptionInfo(
SendToNegative.DEFAULT_TAG_START,
label="Tag start",
section=section,
),
)
shared.opts.add_option(
key="stn_tagend",
info=shared.OptionInfo(
SendToNegative.DEFAULT_TAG_END,
label="Tag end",
section=section,
),
)
shared.opts.add_option(
key="stn_tagparamstart",
info=shared.OptionInfo(
SendToNegative.DEFAULT_TAG_PARAM_START,
label="Tag parameter start",
section=section,
),
)
shared.opts.add_option(
key="stn_tagparamend",
info=shared.OptionInfo(
SendToNegative.DEFAULT_TAG_PARAM_END,
label="Tag parameter end",
section=section,
),
)
shared.opts.add_option(
key="stn_separator",
info=shared.OptionInfo(
Expand All @@ -84,6 +52,14 @@ def __on_ui_settings(self):
section=section,
),
)
shared.opts.add_option(
key="stn_joinattention",
info=shared.OptionInfo(
True,
label="Join attention modifiers (weights) when possible",
section=section,
),
)
shared.opts.add_option(
key="stn_cleanup",
info=shared.OptionInfo(
Expand Down
Loading

0 comments on commit c8a7b6c

Please sign in to comment.