auto-sd-paint-ext icon indicating copy to clipboard operation
auto-sd-paint-ext copied to clipboard

The extension doesn't work at all (img2img() missing 3 required positional arguments)

Open Miraihi opened this issue 1 year ago • 53 comments

Describe the bug Getting the error each time I click "start inpaint/img2img/txt2img" in Krita.

To Reproduce Steps to reproduce the behavior:

  1. Insert any settings
  2. Click "start inpaint/img2img/txt2img"

Screenshots WB0N0DR

auto-sd-paint-ext:WARNING: Interrupted!
auto-sd-paint-ext:INFO: img2img:
{'restore_faces': False, 'face_restorer': 'None', 'codeformer_weight': 0.0, 'inpainting_fill': 1, 'inpaint_full_res': False, 'inpaint_full_res_padding': 0, 'mask_blur': 0, 'invert_mask': False, 'inpaint_mask_weight': 1.0, 'sd_model': 'anything-v4.5-inpainting.safetensors [6d9a152b7a]', 'sd_vae': 'blessed2.vae.pt', 'clip_skip': 2, 'script': 'None', 'script_args': [], 'prompt': 'flawless, highly detailed, high resolution, sharp focus, 4k, vivid colors, best quality, perfect lighting, trending on artstation', 'negative_prompt': 'Negative_ng_deepnegative_v1_75t, Negative_badhandv4, (extra fingers, deformed hands:1.15), (worst quality, low quality, poor quality, bad quality:1.35), logo, watermark, text', 'seed': -1, 'seed_enable_extras': False, 'subseed': -1, 'subseed_strength': 0.0, 'seed_resize_from_h': 0, 'seed_resize_from_w': 0, 'sampler_name': 'DPM++ 2M Karras', 'steps': 20, 'cfg_scale': 10.0, 'denoising_strength': 0.4, 'batch_count': 1, 'batch_size': 1, 'base_size': 512, 'max_size': 768, 'disable_sddebz_highres': False, 'tiling': False, 'highres_fix': False, 'firstphase_height': 512, 'firstphase_width': 512, 'upscaler_name': 'None', 'filter_nsfw': False, 'include_grid': False, 'sample_path': 'outputs/krita-out', 'save_samples': True, 'is_inpaint': True, 'resize_mode': 1, 'color_correct': True, 'do_exact_steps': True}
auto-sd-paint-ext:INFO: img size: 1074x1432 -> 512x688, aspect ratio: 0.75 -> 0.74, -0.78% change
*** Error completing request
*** Arguments: ('', 4, 'flawless, highly detailed, high resolution, sharp focus, 4k, vivid colors, best quality, perfect lighting, trending on artstation', 'Negative_ng_deepnegative_v1_75t, Negative_badhandv4, (extra fingers, deformed hands:1.15), (worst quality, low quality, poor quality, bad quality:1.35), logo, watermark, text', 'None', <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=1074x1432 at 0x2387BFC8A00>, None, None, None, None, <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=1074x1432 at 0x2387BFC8A00>, <PIL.Image.Image image mode=L size=1074x1432 at 0x2387BD3C910>, 20, 2, 0, None, 1, False, False, 1, 1, 10.0, 0, 0.4, -1, -1, 0.0, 0, 0, False, 1, 688, 512, 1.0, 1, False, 0, False, '', '', '', [], 0) {}
    Traceback (most recent call last):
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 58, in f
        res = list(func(*args, **kwargs))
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 37, in f
        res = func(*args, **kwargs)
    TypeError: img2img() missing 3 required positional arguments: 'img2img_batch_png_info_props', 'img2img_batch_png_info_dir', and 'request'

Desktop (please complete the following information):

  • OS: Windows 11 64 bit.
  • WebUI commit revision: 4873e6aaba62c2fa2e4481798e85098e50e1e2c6
  • Extension commit revision: 00714355890aefa9a09e7fdb1f9a136c46a17618

Additional context Doesn't work since 1.5.1 Automatic update. Worked fine before that.

Miraihi avatar Jul 30 '23 14:07 Miraihi

I've fixed this on my local copy a few times now. A few weeks ago I had it working, then the SD XL updates it broke again, and I fixed it once again. This method will help you fix it each time it breaks in the future. I'm using SD.Next (vlads), but the process should be identical for A1111

extensions\auto-sd-paint-ext\backend\app.py has a list of parameters it uses to call txt2img and img2img, as part of def f_txt2img and def f_img2img respectively. Both lists of parameters start on lines that have output = wrap_gradio_gpu_call. These parameters should correspond to the parameters in modules\txt2img.py's def txt2img and modules\img2img.py's def img2img. BUT It seems like the modules keep getting updated, adding and removing required parameters, which in turn breaks this extension.

The quick-and-dirty way to fix the extension each time it breaks is to open up those modules and go item by item through their parameters and line them up with the app.py version. After you've done that, save app.py and restart your stable diffusion server. When you try to use the Krita extension, you'll see a lot of output in the server logs, including errors, but it should work.

It's tedious, it sucks, and I'm sure there's a better way to do it, but for right now that's what you need to do.

DrCyanide avatar Aug 02 '23 10:08 DrCyanide

Same her, getting following errors:- *** Error completing request *** Arguments: ('', '', '', 'None', 20, 6, False, False, 1, 1, 7.0, -1, -1, 0.0, 0, 0, False, 512, 512, False, 0.7, 0, 'None', 0, 512, 512, [], 0) {} Traceback (most recent call last): File "F:\AI\Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 58, in f res = list(func(*args, **kwargs)) File "F:\AI\Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 37, in f res = func(*args, **kwargs) TypeError: txt2img() missing 3 required positional arguments: 'hr_negative_prompt', 'override_settings_texts', and 'request'


auto-sd-paint-ext:WARNING: Interrupted! WARNING:auto-sd-paint-ext:Interrupted!

Fhalo48 avatar Aug 02 '23 14:08 Fhalo48

@DrCyanide Thanks for a really good hint, I was wondering what I can do myself about that! Unfortunately, I still can't figure out the value for the "request" argument.

Getting such error

*** Error completing request
*** Arguments: ('', 4, 'flawless, highly detailed, high resolution, sharp focus, 4k, vivid colors, best quality, perfect lighting, trending on artstation', 'Negative_ng_deepnegative_v1_75t, Negative_badhandv4, (extra fingers, deformed hands:1.15), (worst quality, low quality, poor quality, bad quality:1.35), logo, watermark, text', 'None', <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=583x424 at 0x141F24995D0>, None, None, None, None, <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=583x424 at 0x141F24995D0>, <PIL.Image.Image image mode=L size=583x424 at 0x141F249B400>, 20, 2, 0, None, 1, False, False, 1, 1, 10.0, 0, 0.4, -1, -1, 0.0, 0, 0, False, 1, 512, 704, 1.0, 1, False, 0, False, '', '', '', [], '', '', 1, 0) {}
    Traceback (most recent call last):
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 58, in f
        res = list(func(*args, **kwargs))
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 37, in f
        res = func(*args, **kwargs)
      File "E:\AI\stable-diffusion-webui-directml\modules\img2img.py", line 214, in img2img
        p.user = request.username
    AttributeError: 'int' object has no attribute 'username'

---
auto-sd-paint-ext:WARNING: Interrupted!

What I did exactly is wedged


        "", # img2img_batch_png_info_props
        "", # img2img_batch_png_info_dir
        req.username, # request

between [], # override_settings_texts (unsupported) and *args,.

In img2img.py the "request" argument looks like that: ...request: gr.Request, *args):

I tried just putting "gr.Request" as a string like "gr.Request", # request but it still doesn't work, as well as leaving the quotes empty.

Miraihi avatar Aug 02 '23 14:08 Miraihi

Have you tried passing None in for the request? I know many months ago I was using A1111 with Gradio auth, but the API requests that auto-sd-paint-ext made didn't need any username or password. It's possible they've changed it, but try the easiest thing first.

DrCyanide avatar Aug 02 '23 15:08 DrCyanide

@DrCyanide None produces the same error unfortunately. Switching to vladmandic (SD.Next) is also the option, but it updates way too often so that's not too optimal as I see it.

Miraihi avatar Aug 02 '23 15:08 Miraihi

@DrCyanide None produces the same error unfortunately.

None gives you an error that says 'int' object has no attribute 'username'? Where else did you add a .username then?

DrCyanide avatar Aug 02 '23 15:08 DrCyanide

Yes, exactly the same error that traces back to modules\img2img.py", line 214 p.user = request.username. I didn't modify anything except app.py.

Miraihi avatar Aug 02 '23 15:08 Miraihi

Have you restarted A1111 after saving your changes to app.py? Because the only way you should be able to get that error is if you skipped that last step, and A1111 is using the cached version of app.py.

DrCyanide avatar Aug 02 '23 15:08 DrCyanide

I restart it properly after each change.

Miraihi avatar Aug 02 '23 15:08 Miraihi

I restart it properly after each change.

What's "properly" in this case? Through the UI? I don't know if that does a full restart. Try killing it in the command line and starting it up from scratch.

DrCyanide avatar Aug 02 '23 15:08 DrCyanide

"Properly" means pressing ctrl+c on cmd window and closing it. Look, I wouldn't come that far without knowing such basic things.

Miraihi avatar Aug 02 '23 15:08 Miraihi

Just needed to make sure. In that case, double check the entire list of parameters in app.py. When I first started trying to fix this I was just adding the one parameter that the error message gave, without realizing there were duds left earlier in the line. My guess is you forgot to remove the no longer supported parameters (not to be confused with app.py's "unused" parameters), and it's causing an offset issue (which explains why it thinks you've got an int where you put a None).

As a longer term fix, I think it might be possible to name each parameter that's passed in (example: (id_task="", init_img=image, ...) to make it easier to maintain. No longer supported arguments would so up with an error unexpected keyword argument 'old_dead_param', and missing params would show up as missing 1 required positional argument: 'new_param'.

DrCyanide avatar Aug 02 '23 16:08 DrCyanide

@DrCyanide There has actually been the offset issue (I didn't put one argument that sd-auto wasn't complaining about). But the error stays pretty much the same, with the minor changes

*** Error completing request
*** Arguments: ('', 4, 'flawless, highly detailed, high resolution, sharp focus, 4k, vivid colors, best quality, perfect lighting, trending on artstation', 'Negative_ng_deepnegative_v1_75t, Negative_badhandv4, (extra fingers, deformed hands:1.15), (worst quality, low quality, poor quality, bad quality:1.35), logo, watermark, text', 'None', <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=516x301 at 0x2AB30EBBF70>, None, None, None, None, <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=516x301 at 0x2AB30EBBF70>, <PIL.Image.Image image mode=L size=516x301 at 0x2AB30EBB2E0>, 20, 2, 0, None, 1, False, False, 1, 1, 10.0, 0, 0.4, -1, -1, 0.0, 0, 0, False, 1, 448, 768, 1.0, 1, False, 0, False, '', '', '', [], False, [], '', None, 0) {}
    Traceback (most recent call last):
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 58, in f
        res = list(func(*args, **kwargs))
      File "E:\AI\stable-diffusion-webui-directml\modules\call_queue.py", line 37, in f
        res = func(*args, **kwargs)
      File "E:\AI\stable-diffusion-webui-directml\modules\img2img.py", line 214, in img2img
        p.user = request.username
    AttributeError: 'NoneType' object has no attribute 'username'

---
auto-sd-paint-ext:WARNING: Interrupted!

It's still a mystery how to get around that "username".

Right now the last few lines of img2img section of my app.py look like that

        [],  # override_settings_texts (unsupported)
        False,  # img2img_batch_use_png_info
        [],  # img2img_batch_png_info_props
        "",  # img2img_batch_png_info_dir
        None,  # request
        *args,

Miraihi avatar Aug 02 '23 16:08 Miraihi

Well, that's progress at least!

There's built-in API documentation for A1111 that might explain how to populate the request parameter correctly. This wiki link doesn't have a screenshot of the current version, but if you follow the steps (and the built-in version is updated) then it might be the last step you need.

https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API

DrCyanide avatar Aug 02 '23 17:08 DrCyanide

Well, I tried. But it's time to realize I'm not good enough to really fix it myself, so for the time being I'll be using Photoshop extension that seems to be working just fine.

Miraihi avatar Aug 02 '23 17:08 Miraihi

I know you said you're done with it, but I have one last idea to try if you (or someone else reading this down the road) is willing to try it.

Just doing a quick search of the code, it looks like request is only a parameter so it can pass request.username into another variable p.user, which in turn gets processed by either the txt2img or img2img. The only place that .user variable is used seems to be in modules\processing.py if you've set an option to add the username to the info. In other words, it's not for security, and it's barely used at all.

Since it's basically unused, this could make for an easy fix for A1111 users. Add import gradio as gr to the top with the imports, then a simple gr.Request() in your parameters where the request param shows up.

DrCyanide avatar Aug 03 '23 03:08 DrCyanide

hi ! I also have the exact same problem and tried to slove but i couldn't, I am also too bad to fix it (ended up with a few more error for gr and user.img2img). Just wanted to say thx for trying to help !

bakasephi avatar Aug 03 '23 09:08 bakasephi

I have follow along posts and i got it to work in the end.

first i added the gradio to the import in app.py

from __future__ import annotations

import logging
import os
import time
import gradio as gr #added by user

and after that i go down past output = wrap_gradio_gpu_call(modules.img2img.img2img) to add the new args

        [],  # override_settings_texts (unsupported)
		False,	# img2img_batch_use_png_info (added by user)
		[],	# img2img_batch_png_info_props (added by user)
		"",	# img2img_batch_png_info_dir (added by user)
		gr.Request(),	# request (added by user)
        *args,

@DrCyanide and @Miraihi thanks for the post it was really helpfull

Ripsomeone avatar Aug 03 '23 09:08 Ripsomeone

Hi

Great!! It works to img2img, any syggestions for txt2img?

Fhalo48 avatar Aug 03 '23 10:08 Fhalo48

Oh yep its working ! Thx ! And for txt2img I added the same lines in output = wrap_gradio_gpu_call(modules.txt2img.txt2img) in app.py and its working for me.

bakasephi avatar Aug 03 '23 10:08 bakasephi

I;ll try again for txt2img

Fhalo48 avatar Aug 03 '23 10:08 Fhalo48

In my case I'm getting following err: hr_sampler_name=sd_samplers.samplers_for_img2img[hr_sampler_index - 1].name if hr_sampler_index != 0 else None, TypeError: unsupported operand type(s) for -: 'list' and 'int'

my code layout

        req.orig_width,  # hr_resize_x
        req.orig_height,  # hr_resize_y
        [],  # override_settings_texts (unsupported)
            False,	# img2img_batch_use_png_info (added by user)
            [],	# img2img_batch_png_info_props (added by user)
            "",	# img2img_batch_png_info_dir (added by user)
            gr.Request(),	# request (added by user)
        *args,

Fhalo48 avatar Aug 03 '23 10:08 Fhalo48

Oh I cheked the wrong lines (sry very tired) you need to replace the arg that gives you errors, for me it was 'hr_prompt', 'hr_negative_prompt', 'override_settings_texts', and 'request' And adapt the code from ripsomeone to thoses new arg and to txt2img instead to img2img For me it works but i still have one error showing so maybe wait for better. (mine might be a fluke since even without fix txt2img was working but with a lot of errors). Anyway too tired to think i'll recheck later with a normal brain. So waiting for someone else might be better

bakasephi avatar Aug 03 '23 11:08 bakasephi

@Fhalo48 hey here is the fix i use for txt2img

add after output = wrap_gradio_gpu_call(modules.txt2img.txt2img)

        req.orig_width,  # hr_resize_x
        req.orig_height,  # hr_resize_y
		0,	#hr_sampler_index (added by user)
		[],	#hr_prompt (added by user)
		[],	#hr_negative_prompt (added by user)
        [],  # override_settings_texts (unsupported)
		gr.Request(),	# request (added by user)
        *args,

Ripsomeone avatar Aug 03 '23 11:08 Ripsomeone

Wow, if only I had found the discussion here before fixing it...

poipoi300 avatar Aug 03 '23 11:08 poipoi300

@DrCyanide Thanks for all the help and solution seeking. @poipoi300 Thank you, your fork works just fine

Miraihi avatar Aug 03 '23 12:08 Miraihi

@Ripsomeone , you are a star.

That works, thank you and everyone else/

Fhalo48 avatar Aug 03 '23 12:08 Fhalo48

@Miraihi It's likely to break in the future again unfortunately. Not even mentioning the random new positional arguments that can be added. For the request object, I'm passing the internal pydantic request objects that I added a "username" field to. It seems like txt2img and img2img are accessing the passed "gradio" request with a generic property accessor, so if they keep doing that it should be as simple as just adding new fields in the pydantic models at least.

I'm considering picking this up since interpause has been inactive for a while, and there is at least one QoL thing I want implemented.

poipoi300 avatar Aug 03 '23 12:08 poipoi300

Hi

Spoken to soon :(

Could some check if the following code is correct fro img2img req.resize_mode, # resize_mode False, # req.inpaint_full_res, # inpaint_full_res 0, # req.inpaint_full_res_padding, # inpaint_full_res_padding req.invert_mask, # inpainting_mask_invert "", # img2img_batch_input_dir (unspported) "", # img2img_batch_output_dir (unsupported) "", # img2img_batch_inpaint_mask_dir (unsupported) [], # override_settings_texts (unsupported) False, # img2img_batch_use_png_info (added by user) [], # img2img_batch_png_info_props (added by user) "", # img2img_batch_png_info_dir (added by user) gr.Request(), # request (added by user) *args,

Fhalo48 avatar Aug 03 '23 12:08 Fhalo48

@Fhalo48 Try my fork.

poipoi300 avatar Aug 03 '23 12:08 poipoi300