adieyal / dynamicprompts

Templating language for generating prompts for text to image generators such as Stable Diffusion
MIT License
124 stars 20 forks source link

Add wrap command #102

Closed akx closed 12 months ago

akx commented 1 year ago

This PR adds a new wrap command.

The test says it all:

IOW, a marker string (3+ regular dots, or 1+ Unicode ellipsis character) within the wrapper component of the wrap command will be replaced with the inner command's sampling result.

This also works for things other than wildcards (despite the branch name):

%{{happy|sad} ... in a {car|plane}$${programmer|dog}}

...

akx commented 1 year ago

WDYT @adieyal?

codecov-commenter commented 1 year ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Files Coverage Δ
src/dynamicprompts/commands/__init__.py 100.00% <100.00%> (ø)
src/dynamicprompts/commands/wrap_command.py 100.00% <100.00%> (ø)
src/dynamicprompts/parser/config.py 100.00% <100.00%> (ø)
src/dynamicprompts/parser/parse.py 98.37% <100.00%> (+0.07%) :arrow_up:
src/dynamicprompts/samplers/combinatorial.py 97.56% <100.00%> (+0.15%) :arrow_up:
src/dynamicprompts/samplers/random.py 96.00% <100.00%> (+0.44%) :arrow_up:
src/dynamicprompts/sampling_result.py 100.00% <100.00%> (ø)
tests/test_wrapping.py 100.00% <100.00%> (ø)
tests/utils.py 100.00% <100.00%> (ø)
tests/wildcard/test_wildcardmanager.py 100.00% <ø> (ø)
... and 1 more

:loudspeaker: Thoughts on this report? Let us know!

adieyal commented 1 year ago

WDYT @adieyal?

I like the general idea of infill, although it feels a little complicated to use. Is the % necessary? Can we not assume that ellipses in the wrapper mean infill? I don't think that would break any existing workflows since the wrappers was only used as a separator before.

Do you have any concrete use cases that you've used it for?

akx commented 1 year ago

I like the general idea of infill, although it feels a little complicated to use. Is the % necessary? Can we not assume that ellipses in the wrapper mean infill? I don't think that would break any existing workflows since the wrappers was only used as a separator before.

I agree it's a bit unwieldy. Without some sort of syntax like this, how would the wrapper know what to wrap? The examples from the tests are

Do you have any concrete use cases that you've used it for?

I've ported the Fooocus style templates from https://github.com/lllyasviel/Fooocus/tree/main/sdxl_styles to wrapping wildcards, and have had fun with that; please enjoy this stably diffused melon:

00059-20231107202053-885656039

akx commented 12 months ago

@adieyal WDYT, should we merge this? I don't think the %{a...c$$b} syntax should be breaking any current workflows, even if it is a bit unwieldy (if someone comes up with a lighter-weight syntax later, we could ship that too)?

adieyal commented 12 months ago

Hey. I went through it this weekend. I think it's a great feature but I was struggling to get it to work. Kept getting syntax errors with my prompts (although the tests passed so I'm not sure why).

Let's merge it if you're happy that it's ready. I'll add to the docs once I've figured out what I'm doing wrong.

On Mon, 20 Nov 2023, 08:54 Aarni Koskela, @.***> wrote:

@adieyal https://github.com/adieyal WDYT, should we merge this? I don't think the %{a...c$$b} syntax should be breaking any current workflows, even if it is a bit unwieldy (if someone comes up with a lighter-weight syntax later, we could ship that too)?

— Reply to this email directly, view it on GitHub https://github.com/adieyal/dynamicprompts/pull/102#issuecomment-1818337528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADGXMRQWTW4A46LJU6WW2TYFL5CJAVCNFSM6AAAAAA7AF44CWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJYGMZTONJSHA . You are receiving this because you were mentioned.Message ID: @.***>