stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: Settings Presets

Open Noctropolitan opened this issue 2 years ago • 16 comments

Is there an existing issue for this?

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

What would your feature do ?

Save and load different options: When using Novel AI's model you have to tweak several options that other models don't require, if you change back into the Standard SD Model (or another different one) you have to manually disable those options to the other model to work properly. Also, adjusting settings seeds, ddim steps or prompts, saving those and loading them for future use.

Proposed workflow

  1. Go to Settings
  2. Adjusts the Settings and Options that you need
  3. Click a new "Save Custom Settings" button
  4. In main Menu you could "Save parameters" to save prompt, seeds, ddim, cfg scale, sampling method, etc
  5. Load the Custom settings or your custom parameters anytime, allowing you to pick between previously saved configurations.

Additional information

No response

Noctropolitan avatar Oct 27 '22 20:10 Noctropolitan

I can vouch for that in the form of a snapshot library, at the very least in the main tabs.

My workflow is very often as follows:

  1. Generate tons of pics at 20DDIM samples
  2. Find a good image
  3. Reuse the seed but this time at 60+ DDIM samples & only generate one image
  4. Rince and repeat for inpainting/finetuning details of the image

I would love to have some snapshots at the top of the ui, with favorites ones so they can be one click away. I don't think this would be too hard as the "send to XXX" buttons already kinda do this by grabbing it from the exif I believe, but the presets could just be some json presets stored somewhere

Mozoloa avatar Oct 27 '22 20:10 Mozoloa

I change a few things in ui-config.json, but I would suggest keeping a backup to extract settings when there is an update that replaces this file. I also use config.json sometimes.

rasamaya avatar Oct 27 '22 20:10 rasamaya

I change a few things in ui-config.json, but I would suggest keeping a backup to extract settings when there is an update that replaces this file. I also use config.json sometimes.

I don't think that's what we're talking about here, it's about quickly switching between ui settings without having to restart, not customising default settings in config jsons

Mozoloa avatar Oct 27 '22 20:10 Mozoloa

makes sense, but setting your defaults, as your typical, sure helped me, now I only remember one or two other goto's vs normally keeping 2-3 in mind. If its a feature we can hide, or disable in settings, that would be best. My screen is becoming very full, but do love these new features.

rasamaya avatar Oct 27 '22 20:10 rasamaya

You can already choose what you want to put up there in the quick settings via an option in the settings so it's defo doable

Mozoloa avatar Oct 27 '22 21:10 Mozoloa

this would be nice, like saving a json of settings as a preset for loading later

Kavukamari avatar Oct 27 '22 21:10 Kavukamari

I actually want to do this in my plugin.

Actually, it should be possible to do using the Extensions API. Maybe I will try if I have time.

I envision it would be an additional webUI tab. Basic features would be search bar for already saved presets, create new preset, rename preset, delete preset. Presets would use settings at point of preset creation.

Probably would be done by iterating the entire shared.opts config object.

Interpause avatar Nov 05 '22 08:11 Interpause

It's possible by getting the information on the page from modules.ui.txt2img_paste_fields & modules.ui.img2img_paste_fields respectvely.

You can do it in the same tab.

Currently I tested it out on putting it in the settings tab, using a callback.

image

Quick and dirty.

image

Then hitting apply settings saves it in the config.json automatically. image

At the moment, I'm trying to understand how the Settings tab handles reading and writing to the config.
This way, I can just target those methods, and send data from the page, and recall data from the page.

Then using gradios gr.Examples, you can have it where a person clicks there setting from a dropdown, and it automatically updates all the fields.

For the situation where the user wants to save as a profile, you can add the profile name to the setting name. But the next method below, might just make it easier to have it sorted just by profile name in a custom json.

If I can't figure out how the settings handles it, in a reasonable amount of time, I'm just going to use json.load and json.dump and write my own file. This might be better, because it wouldn't be touch by a git pull.

Gerschel avatar Dec 06 '22 01:12 Gerschel

Here is the ghettoness in action. Don't judge me, I threw this together while thinking about this while working on another project. I didn't even finish filing in stuff I was adding to put it in the actual tab. It's just half of a poc.

import modules.scripts as scripts
import gradio as gr

import modules
from modules import shared
import modules.ui


from pprint import pprint
from collections import namedtuple


ui_ele = modules.ui.txt2img_paste_fields

class Script(scripts.Script):

    def title(self):
        return "Apply Settings"

    def ui(self, is_img2img):
        UserSetting = namedtuple("UserSetting", ["setting_name", "setting_elements"] )
        SettingElements = namedtuple("SettingElements", ["checkbox", "text"])
        user_settings = []
    
    def run(self, p):
        pprint(ui_ele)



def on_ui_settings():
    Section = namedtuple("Section", ["internal_name", "proper_name"])
    txt2img_section = Section("txt2img_custom_settings", "Txt2Img Custom Settings")
    for txt2img_ui in ui_ele:
        shared.opts.add_option(txt2img_section.internal_name + txt2img_ui[1],
                                shared.OptionInfo(
                                                    default=txt2img_ui[0].value,
                                                    label=txt2img_ui[1],
                                                    component=type(txt2img_ui[0]),
                                                    #component=txt2img_ui[0],
                                                    #component_args=txt2img_ui[0].args,
                                                    #onchange=txt2img_ui[0].onchange,
                                                    section = txt2img_section
                                ))

modules.script_callbacks.on_ui_settings(on_ui_settings)

Gerschel avatar Dec 06 '22 01:12 Gerschel

Alright. I'm going to make it really quick, be right back.

Gerschel avatar Dec 06 '22 01:12 Gerschel

I've hit a snag. Sometimes when I restart, the paste_fields don't exist, when I reapply scripts from settings, they are there. Sometimes, they aren't at all.

This occurs when I put the code in the Scripts.ui method. But this doesn't seem to be an issue when using the callback for the settings page.

Obviously they do exist. It seems to be a race condition. If only I could delay my script from being loaded. Perhaps rename it so it lands at the end of the "Scripts" choices.

image

Gerschel avatar Dec 06 '22 04:12 Gerschel

I think I figured out how to handle it. I don't need those values until the person hits the save button, so I put it in the save function, so it doesn't get asked for until after everything is loaded.

Gerschel avatar Dec 06 '22 05:12 Gerschel

So, apparently those components in that list can't return their current value while in the def ui, so I'm going to attempt to use the generate button as a save. If someone know how I could hook into it more reliably (considered js, but not elements are assigned a specific id, they get one implicitly by gradio, but not explicitly, so it could break on updates).

Gerschel avatar Dec 06 '22 07:12 Gerschel

got it https://github.com/Gerschel/sd_web_ui_preset_utils

Gerschel avatar Dec 15 '22 11:12 Gerschel

Aaaand that repo's gone now

paulsd95 avatar Jan 27 '23 09:01 paulsd95

@paulsd95 I just brought back the version 1, might push version 2 back up in a few days.
I didn't realize how useful it was to others. I got some messages asking about it, so it's back.

Gerschel avatar Jan 27 '23 10:01 Gerschel