adieyal / sd-dynamic-prompts

A custom script for AUTOMATIC1111/stable-diffusion-webui to implement a tiny template language for random prompt generation
MIT License
2.01k stars 259 forks source link

Wildcards in batch img2img #2

Closed Adil3tr closed 1 year ago

Adil3tr commented 1 year ago

I love wildcards and almost always use them, but there's two functions that can't seem to use them.

The first is batch processing. The wildcards script works but only uses one value for all images in the whole batch count. This dynamic prompting script actually just gives me an error when I try to do batch processing. (batch processing is in the img2img tab, it lets you run img2img on an entire folder of images with the same prompt and values). I would love to be able to use batch processing with dynamic prompting, and a unique combination of wildcard values in every individual image generation in the batch.

The second is wildcard/dynamic negative prompts. I sometimes use wildcards as a way of just adding variability, and I would love to be able to have "(adjective)" as my negative prompt to generate more kinds of variation in my generations. Right now it doesn't seem to recognize a wildcard in the negative text book, and the generated image's txt file just says "adjective" instead of assigning it a value.

adieyal commented 1 year ago

I'll take a look

adieyal commented 1 year ago

I just made a change to address the batch img2img issue that you raised. Could you please test it and let me know if it works for you?

adieyal commented 1 year ago

I don't think I can fix your negative prompt request though given how they are dealt with in the main repo. Right now, multiple prompts are allowed, but only a single negative prompt. I'll open an issue there to see if there is any interest in changing how it works.

Adil3tr commented 1 year ago

I just made a change to address the batch img2img issue that you raised. Could you please test it and let me know if it works for you?

No, it's still not working.

Error completing request
Arguments: (2, 'Cat, by __artist__', '', 'None', 'None', None, None, None, None, 0, 50, 2, 4, 0, False, False, 1, 1, 10, 0.7, -1.0, -1.0, 0, 0, 0, False, 512, 512, 0, False, 32, 0, 'F:\\AI\\For Stable Diffusion', '', 3, True, False, '', '', '\n            <h3><strong>Combinations</strong></h3>\n            Choose a number of terms from a list, in this case we choose two artists\n            <code>{2$$artist1|artist2|artist3}</code>\n            If $$ is not provided, then 1$$ is assumed.\n            <br/><br/>\n\n            <h3><strong>Wildcards</strong></h3>\n            <p>Available wildcards</p>\n            <ul>\n        <li>__adjective__</li><li>__animal__</li><li>__artist__</li><li>__artist2__</li><li>__color__</li><li>__detail__</li><li>__format__</li><li>__format2__</li><li>__genre__</li><li>__newsubject__</li><li>__pattern__</li><li>__person__</li><li>__personaction__</li><li>__photoformat__</li><li>__photoformattest__</li><li>__photographer__</li><li>__site__</li><li>__sports__</li><li>__styletest__</li><li>__subject__</li></ul>\n            <br/>\n            <code>WILDCARD_DIR: scripts/wildcards</code><br/>\n            <small>You can add more wildcards by creating a text file with one term per line and name is mywildcards.txt. Place it in scripts/wildcards. <code>__mywildcards__</code> will then become available.</small>\n        ', '<ul>\n<li><code>CFG Scale</code> should be 2 or lower.</li>\n</ul>\n', True, True, '', '', True, 50, True, 1, 0, False, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, None, '', '<p style="margin-bottom:0.75em">Will upscale the image to twice the dimensions; use width and height sliders to set tile size</p>', 64, 0, '', '', 100, 0, 0, True, '<div class="gr-block gr-box relative w-full overflow-hidden border-solid border border-gray-200 gr-panel"><p>If you like my work, please consider showing your support on <strong><a href="https://patreon.com/thereforegames" target="_blank">Patreon</a></strong>. Thank you! &#10084;</p></div>', False, 1, '', 0, '', True, True, False) {}
Traceback (most recent call last):
  File "F:\Stable Diffusion\stable-diffusion-webui-master\modules\ui.py", line 212, in f
    res = list(func(*args, **kwargs))
adieyal commented 1 year ago

Is that the complete error message? What you've pasted above doesn't originate from the dynamic prompting script. Is there more?

adieyal commented 1 year ago

Btw - I have moved the negative prompt request to another issue

Adil3tr commented 1 year ago

Is that the complete error message? What you've pasted above doesn't originate from the dynamic prompting script. Is there more?

It's somehow gotten worse, I'm getting it with any form of img2img

Error completing request Arguments: (0, '__genre__ (American) vibe, (__format__), by __artist2__, ultra detailed, 4k, sharp focus, __adjective__, flags', '', 'None', 'None', <PIL.Image.Image image mode=RGB size=2304x2304 at 0x1F794843F40>, None, None, None, 0, 50, 2, 4, 0, False, False, 1, 1, 10, 0.75, -1.0, -1.0, 0, 0, 0, False, 512, 512, 0, False, 32, 0, '', '', 3, True, False, '', '', '\n <h3><strong>Combinations</strong></h3>\n Choose a number of terms from a list, in this case we choose two artists\n <code>{2$$artist1|artist2|artist3}</code>\n If $$ is not provided, then 1$$ is assumed.\n <br/><br/>\n\n <h3><strong>Wildcards</strong></h3>\n <p>Available wildcards</p>\n <ul>\n <li>__adjective__</li><li>__animal__</li><li>__artist__</li><li>__artist2__</li><li>__color__</li><li>__detail__</li><li>__format__</li><li>__format2__</li><li>__genre__</li><li>__newsubject__</li><li>__pattern__</li><li>__person__</li><li>__personaction__</li><li>__photoformat__</li><li>__photoformattest__</li><li>__photographer__</li><li>__site__</li><li>__sports__</li><li>__styletest__</li><li>__subject__</li></ul>\n <br/>\n <code>WILDCARD_DIR: scripts/wildcards</code><br/>\n <small>You can add more wildcards by creating a text file with one term per line and name is mywildcards.txt. Place it in scripts/wildcards. <code>__mywildcards__</code> will then become available.</small>\n ', '<ul>\n<li><code>CFG Scale</code> should be 2 or lower.</li>\n</ul>\n', True, True, '', '', True, 50, True, 1, 0, False, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, None, '', '<p style="margin-bottom:0.75em">Will upscale the image to twice the dimensions; use width and height sliders to set tile size</p>', 64, 0, '', '', 100, 0, 0, True, '<div class="gr-block gr-box relative w-full overflow-hidden border-solid border border-gray-200 gr-panel"><p>If you like my work, please consider showing your support on <strong><a href="https://patreon.com/thereforegames" target="_blank">Patreon</a></strong>. Thank you! &#10084;</p></div>', False, 1, '', 0, '', True, True, False) {} Traceback (most recent call last): File "F:\Stable Diffusion\stable-diffusion-webui-master\modules\ui.py", line 212, in f res = list(func(*args, **kwargs)) File "F:\Stable Diffusion\stable-diffusion-webui-master\webui.py", line 64, in f res = func(*args, **kwargs) File "F:\Stable Diffusion\stable-diffusion-webui-master\modules\img2img.py", line 124, in img2img processed = modules.scripts.scripts_img2img.run(p, *args) File "F:\Stable Diffusion\stable-diffusion-webui-master\modules\scripts.py", line 159, in run processed = script.run(p, *script_args) File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 151, in run all_prompts = [ File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 152, in <listcomp> generate_prompt(original_prompt) for _ in range(p.n_iter) File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 109, in generate_prompt return pick_wildcards(pick_variant(template)) File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 72, in pick_wildcards return re_wildcard.sub(replace_wildcard, template) File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 68, in replace_wildcard options = [line.strip() for line in wildcard_path.open()] File "F:\Stable Diffusion\stable-diffusion-webui-master\scripts\dynamic_prompting.py", line 68, in <listcomp> options = [line.strip() for line in wildcard_path.open()] File "C:\Users\Adil3\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 3622: character maps to <undefined>

Adil3tr commented 1 year ago

I now realize that the issue is with a character in my artists wildcard, but the wildcard works in the Wildcards script, just not the dynamic prompts one. Is there a reason this script can't recognize all characters that the other one can? I assume it's an accent in an artist's name.

adieyal commented 1 year ago

Could you share the file that's breaking the script so that I can test it?

adieyal commented 1 year ago

Could you test 0.4.3? I tried your file and it seems fine.

Adil3tr commented 1 year ago

It's working now! Thanks.