AlUlkesh / stable-diffusion-webui-images-browser

an images browse for stable-diffusion-webui
625 stars 111 forks source link

Sending to txt2img/img2img tab while using an UmiAI wildcard (for example) still causes errors (red labels everywhere in mentioned tabs). #83

Closed mart-hill closed 1 year ago

mart-hill commented 1 year ago

It's like I mentioned in the title, and I already reposted it back in the time for the WebUI, but it's probably dynamic prompts extension's fault?

When I "paste" an image with "clean" info (without a Wildcard prompt: "blablabla" part in the file info), the error disappears and I'm able to continue. 🙂 Otherwise, I'll get this:

Traceback (most recent call last):
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 337, in run_predict
    output = await app.get_blocks().process_api(
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "O:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "O:\AI\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 340, in paste_func
    params = parse_generation_parameters(prompt)
  File "O:\AI\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 264, in parse_generation_parameters
    v = v[1:-1] if v[0] == '"' and v[-1] == '"' else v
IndexError: string index out of range

This error is also happening while using PNG Info tab, so, in the end, it's a wider issue, but maybe at least in this extension, it could be "workaround'ed"? 😅

Would it be possible for the Images Browser to insert the "wildcard" part of the text to the positive prompt, if/when the extension encounters it? I think, that, at least in UmiAI's case, that extension doesn't react to its "tags", when inserted into the negative prompt area. I used the "classroom" tag from UmiAI with such <[classroom]> syntax. That causes the Umi to make a random choosing of the parts, which are included as a description of this tag in Umi's .yaml file.

Example generation, which causes error on "import" to txt2img:

img

f0lie commented 1 year ago

For clarity, the pnginfo looks like this:

image

I was able to reproduce this problem on my machine as well.

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8/modules/generation_parameters_copypaste.py#L264

The offending line is here. It looks like it has to do with logic in the main repo instead of this repo. Fixes would have to be done in a pull request over there and right now the PRs are being stalled for some reason.

f0lie commented 1 year ago

After running the debugger the root of the problem is that the value field of "File Includes" is empty.

Screenshot 2023-03-10 195829

The line I linked tries to read from this empty string and throws an error. I am not sure what "File Includes" means in the context of the extension that creates this.

There are two ways to solve this problem:

  1. Update automatic1111 main repo to handle empty strings correctly.
  2. Update the extension that is adding "File Includes" to not include empty lines.

I think (1) is better but the main repo is not accepting PRs for some reason. It would be as simple as checking to make sure that v is not empty.

It's clear that this problem can't be fixed in this repo. So you probably have to open a bug on another extension or the main repo.

(Btw, debuggers are amazing and everyone should use them.)

mart-hill commented 1 year ago

Thank you for the insight, @f0lie!

f0lie commented 1 year ago

@mart-hill If you want to patch it on your local repo, just go to offending line change the line to:

if v:
  v = v[1:-1] if v[0] == '"' and v[-1] == '"' else v

It shouldn't change the behave of anything else. It seems like that code is trying to remove quotes from parsed inputs. I guess they did that because the regex was already getting long.

mart-hill commented 1 year ago

Thank you so much! I'll try this instant! 🙂

Edit: It fixes the issue, indeed! Thank you! :)

mart-hill commented 1 year ago

I'll mention, that main AUTO1111 repo maintainer finally patched it, I believe. I no longer needed to edit generation_parameters_copypaste.py file after today's git pull.🙂

f0lie commented 1 year ago

It seems like they fixed the regex itself as opposed to the hotfix I suggested. It's better to fix root cause problems than patchy hacks.

mart-hill commented 1 year ago

Oh. though, I noticed that the if v: stayed in that file on my side, since I didn't have to remove it, when I used git pull a hour and a half ago. Curious, because the repo has this .py file without your "patchy hack" 🙂 I'll use git pull again and test!

mart-hill commented 1 year ago

I checked and the generation_parameters_copypaste.py file from the main repo doesn't have this issue fixed for now, so I'll edit the .py file to add if v:.🙂