Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Checkbox default state breaks in scripts if using a label - possibly a Gradio bug? #6109

Closed
1 task done
ThereforeGames opened this issue Dec 29, 2022 · 9 comments
Closed
1 task done
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@ThereforeGames
Copy link
Contributor

ThereforeGames commented Dec 29, 2022

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What happened?

Hi,

This issue seems to apply to both scripts and extensions.

Try creating a checkbox inside of the ui() routine like so:

EDIT: updated example for clarity.

gr.Checkbox(label="Anything",value=True)

Head over to the WebUI, and you'll find that the default state of the checkbox might be true or false regardless of the value you set. It seems to depend on the label, which is bizarre.

If you remove the label outright then the value works as expected, e.g.

gr.Checkbox(value=True)

Has this been reported before? I didn't see anything like it in Gradio's Issue Tracker, so I think it's probably an issue with the A1111 WebUI but I'm not 100% sure.

I tried modifying the checkboxes in scripts made by other users and found they exhibited the same problem.

Steps to reproduce the problem

See above

What should have happened?

The value of a Gradio checkbox should determine its default state (checked or not-checked) regardless of the label field. Per Gradio's docs: https://www.gradio.app/docs/#checkbox

Commit where the problem happens

4af3ca5

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Brave

Command Line Arguments

N/A

Additional information, context and logs

N/A

@ThereforeGames ThereforeGames added the bug-report Report of a bug, yet to be confirmed label Dec 29, 2022
@AlUlkesh
Copy link
Contributor

I just tried this a few times, but your example

gr.Checkbox(label="Anything",value=False)

always gives me a False default. I tried it on FIrefox and Brave on Windows.

Is there perhaps an extension that messes with your UI?

@ThereforeGames
Copy link
Contributor Author

ThereforeGames commented Dec 30, 2022

always gives me a False default. I tried it on FIrefox and Brave on Windows.

Hmm, I suppose that was a poor example; the "Anything" label will always create an unchecked box. If I set the value to True, it is still unchecked.

Here is video evidence:

NVIDIA_Share_LLoc7KsS9d.mp4

Some labels cause the opposite problem (always checked regardless of value.)

EDIT: Same issue on Microsoft Edge, so I don't think it's due to a browser extension.

@AlUlkesh
Copy link
Contributor

AlUlkesh commented Dec 30, 2022

Ah, can confirm now. Both in an extension or the main UI this seems to always give an unchecked checkbox, despite the default being set to true.

@ThereforeGames
Copy link
Contributor Author

Thanks @AlUlkesh. Glad to know it's not just me!

I found a workaround, although it's somewhat inconvenient.

According to Gradio docs, you can set the value of a checkbox to a callable function, which is deferred until the app is done loading. You can use this in conjunction with label without running into weird problems.

# Workaround for Gradio checkbox label+value bug https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/6109
def gradio_enabled_checkbox_workaround():
	return(Unprompted.Config.ui.enabled)
is_enabled = gr.Checkbox(label="Enabled",value=gradio_enabled_checkbox_workaround)

Not sure if it's possible to pass arguments into the value function. I'm hoping you don't have to set up a workaround function for each and every checkbox. If you can't pass arguments, then I guess you could probably use a global variable to control the return statement.

@AlUlkesh
Copy link
Contributor

I think I figured out what's going on. It's all happening in the loadsave-function:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/ui.py#L1707

Turns out the checkbox value is stored in ui-config.json the first time it appears in the code.

On any subsequent start, it's then loaded from there.

    "txt2img/Anything/visible": true,
    "txt2img/Anything/value": false,

So, the behaviour is actually not dependent on the label-name, but on what it was set to the very first time.

A manual solution would then be to edit ui-config.json and delete the lines. On the next start it should then be saved as the correct default value.

This should be a non-issue for the normal user, since they don't change the first default. Annoying as a developer though.

@ThereforeGames
Copy link
Contributor Author

ThereforeGames commented Dec 31, 2022

I think I figured out what's going on. It's all happening in the loadsave-function:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/ui.py#L1707

Oh, that would explain it! Nice find.

I guess this is intended behavior then. It's cool that the WebUI can preserve settings, but what if you need to change a default for better user experience? It sounds like users would be stuck with their old settings if they had ever launched the script before.

Also, is the ui-config.json file supposed to update itself with your current settings whenever the app closes? I don't think that's been my experience. Seems like a one time deal.

@AlUlkesh
Copy link
Contributor

I'm also scratching my head over this line in the loadsave-function:

            if getattr(obj, 'do_not_save_to_config', False):
                return

This seems to imply there's a way to prevent the save, but I don't know how one would set this attribute for a checkbox.

@ThereforeGames
Copy link
Contributor Author

Hey @AlUlkesh,

I recently needed to manage the default state of a checkbox and was able to get the "do_not_save_to_config" attribute working.

You can use it like this:

obj = gr.Checkbox(label="Some label",value=True)
setattr(obj,"do_not_save_to_config",True)

The only caveat is that you will need to manually delete any existing entries for the element in ui-config.json. But, it won't be written there again in the future.

Will mark this issue as closed.

@AlUlkesh
Copy link
Contributor

Oh, very nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests

2 participants