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

Add support for configuring UI defaults #40

Merged
merged 1 commit into from Aug 26, 2022

Conversation

green-s
Copy link
Contributor

@green-s green-s commented Aug 25, 2022

Adds support for configuring UI default values using the same configuration file format used for the --cli parameter. By default it looks for the file in configs/webui/webui.yaml. The target parameter is currently unused but could be used to select the default tab, however I don't see an option for that in Gradio.

@green-s green-s force-pushed the defaults-support branch 4 times, most recently from 8b0ad50 to 0a07693 Compare Aug 25, 2022
@hlky
Copy link
Owner

hlky commented Aug 25, 2022

dont think it's possible to set tab

good work though, are you going to implement for img2img too?

you could use the defaults from code if there's no file?

@hlky hlky added enhancement New feature or request wip labels Aug 25, 2022
@green-s
Copy link
Contributor Author

green-s commented Aug 25, 2022

Could do, however I'm not sure how best to handle it. The toggles have different indices, and you currently set the cfg_scale to 5.0 in img2img but 7.5 in txt2img. Should I move the two img2img loopback toggles to the end (to keep the indices of the rest the same across both) and default cfg_scale for both to 7.5?

@hlky
Copy link
Owner

hlky commented Aug 25, 2022

why not txt2img.yaml and img2img.yaml?

can you add the txt2img.yaml file

@green-s
Copy link
Contributor Author

green-s commented Aug 26, 2022

why not txt2img.yaml and img2img.yaml?

Could do, but in that case should I remove the --defaults cli arg and just hardcode the paths? Another option is to stick with the one config file but with two objects/sections.

@hlky
Copy link
Owner

hlky commented Aug 26, 2022

up2u i dont see many people using it anyway really

as long as it doesnt break anything i dont mind

@green-s
Copy link
Contributor Author

green-s commented Aug 26, 2022

Just updated it with img2img and gfpgan support. Went for one file with multiple sections.

webui.py Outdated
@@ -680,6 +681,11 @@ def flag(self, flag_data, flag_option=None, flag_index=None, username=None):

print("Logged:", filenames[0])

if opt.defaults is not None and os.path.isfile(opt.defaults):
with open(opt.defaults, "r", encoding="utf8") as f:
user_defaults = yaml.safe_load(f)
Copy link
Owner

@hlky hlky Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the user specifies an incorrect file?

You might think it won't happen but there's always a chance of major pebkac so it could

Copy link
Contributor Author

@green-s green-s Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much the same thing that happens with the --cli arg currently. It just crashes. I'll add a fallback to defaults if the file can't be parsed at all but I don't know if it's worth doing more validation for this.

webui.py Outdated
with open(opt.defaults, "r", encoding="utf8") as f:
user_defaults = yaml.safe_load(f)
else:
user_defaults = {}
Copy link
Owner

@hlky hlky Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't really ever reach this, but pebkac again, if the user specifies a path that is not a file it will

Copy link
Contributor Author

@green-s green-s Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they do and it doesn't parse as yaml then the program will just crash currently. If it does parse but doesn't have any relevant keys, they won't overwrite the defaults. The update method merges dicts. Merging with an empty one does nothing essentially.

webui.py Outdated
'Save individual images',
'Save grid'
]
txt2img_defaults = {
Copy link
Owner

@hlky hlky Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set this on user_defaults if the above pebkac caused issue occurs?

Copy link
Owner

@hlky hlky left a comment

seems good but couple of things to change to stop people breaking things accidentally

@hlky
Copy link
Owner

hlky commented Aug 26, 2022

#44 will have broken your changes, sorry, worth rebasing though because this update is 🔥

@hlky hlky marked this pull request as draft Aug 26, 2022
@green-s green-s force-pushed the defaults-support branch 2 times, most recently from dc7cd05 to 1f53987 Compare Aug 26, 2022
@green-s green-s marked this pull request as ready for review Aug 26, 2022
@hlky hlky merged commit aaa4b9d into hlky:master Aug 26, 2022
@green-s green-s deleted the defaults-support branch Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants