-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Comments
I just tried this a few times, but your example
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? |
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.mp4Some 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. |
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. |
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.
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. |
I think I figured out what's going on. It's all happening in the loadsave-function: 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.
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. |
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 |
I'm also scratching my head over this line in the loadsave-function:
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. |
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:
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. |
Oh, very nice. |
Is there an existing issue for this?
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.
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.
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
Additional information, context and logs
N/A
The text was updated successfully, but these errors were encountered: