LEv145 / --sd-webui-ar-plus

Select img aspect ratio from presets in sd-webui
51 stars 5 forks source link

The "Switch" button errors when clicked [FORGE] #26

Closed LEv145 closed 3 weeks ago

LEv145 commented 3 weeks ago

Error

  File "C:\Users\OFFICE\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\OFFICE\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\OFFICE\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\OFFICE\AppData\Local\Programs\Python\Python310\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)

The above 4 lines repeat many times before...

TypeError: cannot pickle '_thread.lock' object

Possible solution

https://www.gradio.app/docs/gradio/state

LEv145 commented 3 weeks ago

https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper/issues/300

altoiddealer commented 3 weeks ago

It could have something to do with the global variable.

Take a look at how I mitigated the global variables here and here

LEv145 commented 3 weeks ago

https://github.com/LEv145/--sd-webui-ar-plus/tree/fix-forge-arc-logic-buttons

altoiddealer commented 3 weeks ago

I tested this in Forge - the button logic is now working without any errors.

There is a problem though - once clicked, the icon vanishes and does not ever restore.

Unclicked:

Screenshot 2024-08-21 141458

Clicked once:

Screenshot 2024-08-21 141545

Clicked again:

Screenshot 2024-08-21 141434

LEv145 commented 3 weeks ago

I understand, I'll have to recreate the buttons

LEv145 commented 3 weeks ago

https://github.com/LEv145/--sd-webui-ar-plus/commit/27ef14b08751c0bb4c77c06c09cb275745e9d565 https://github.com/LEv145/--sd-webui-ar-plus/commit/310a2df9d72fbdbf1a1252e592fe8d3883101eac

altoiddealer commented 3 weeks ago

27ef14b 310a2df

This makes the whole button disappear when clicked XD

Screenshot 2024-08-21 142846

In my version, I actually change the button value (icon string) when clicked (not the gradio variant attribute for primary/secondary), which is why I change the "value" of the button when clicked.

I think you were close originally but the function was trying to update the value in addition to the variant?

LEv145 commented 3 weeks ago

Oops, I think I made a little mistake in the line :D https://github.com/LEv145/--sd-webui-ar-plus/commit/3199e772b27be1950eb4c2e9297c3a0823478763 https://github.com/LEv145/--sd-webui-ar-plus/commit/00b7978f8425135427f200476e98590127ce7758

The problem here is that the .update() method is deprecated and broken in Gradio 4, so I'm recreating object as the developer advises: https://github.com/gradio-app/gradio/issues/6339

Removes the deprecated .update() method from component classes. Instead, you can now just return an instance of a component from your function. I.e. return gr.Textbox(lines=4) instead of gr.Textbox.update(lines=4)

But gr.update seems to still work https://github.com/altoiddealer/--sd-webui-ar-plusplus/blob/8b900cd2748f95bce455db62ba0cb08093a3ca59/scripts/sd-webui-ar-plusplus.py#L439

LEv145 commented 3 weeks ago

https://github.com/gradio-app/gradio/issues/5863

altoiddealer commented 3 weeks ago

The SD WebUI guys don't just import gradio and call it a day - they have all sorts of patches and stuff that I can't comprehend, which probably convert a lot of bad code into good code. It's very likely that there's something in there fixing the gr.update

I can't claim to understand that code well, I definitely relied hard on your code / ChatGPT.

The new commit is working in Forge... but unfortunately, that button is erroring in A1111

  File "D:\0_AI\stable-diffusion-webui\venv\lib\site-packages\fastapi\encoders.py", line 148, in jsonable_encoder
    if isinstance(obj, classes_tuple):
  File "C:\Users\RandallSu\AppData\Local\Programs\Python\Python310\lib\abc.py", line 119, in __instancecheck__
    return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison
LEv145 commented 3 weeks ago

Okay, then it makes sense to use gr.update

LEv145 commented 3 weeks ago

In theory it should work

https://github.com/LEv145/--sd-webui-ar-plus/commit/670146696391617f922559addb64f30167d79a5b

LEv145 commented 3 weeks ago

I think in Gradio 4 they left the option to use gr.update

But, unfortunately, they did not write how to simply switch from Gradio 3 to Gradio 4

altoiddealer commented 3 weeks ago

Good news! It's now working in A111 and Forge :)

Thanks again for coming up with the solution to our main problem, it was driving me insane!