diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-09-04 10:52:01 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-09-04 10:52:01 +0000 |
commit | 78278ce695beffbf59c7320bb0441922d66b1c0e (patch) | |
tree | b0faf9280ccdbae57034ae2017d92e13dc4219ad | |
parent | 836b6463744e1de1ec57390766c3da4e9f7ee88f (diff) | |
download | stable-diffusion-webui-gfx803-78278ce695beffbf59c7320bb0441922d66b1c0e.tar.gz stable-diffusion-webui-gfx803-78278ce695beffbf59c7320bb0441922d66b1c0e.tar.bz2 stable-diffusion-webui-gfx803-78278ce695beffbf59c7320bb0441922d66b1c0e.zip |
added UI config file: ui-config.json
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | modules/ui.py | 50 |
2 files changed, 49 insertions, 2 deletions
@@ -31,6 +31,7 @@ Original script with Gradio UI was written by a kind anonymous user. This is a m - Settings page
- Running custom code from UI
- Mouseover hints fo most UI elements
+- Possible to change defaults/mix/max/step values for UI elements via text config
## Installing and running
diff --git a/modules/ui.py b/modules/ui.py index 65d53bcd..d6b39c2f 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -133,8 +133,15 @@ def wrap_gradio_call(func): return f
-def create_ui(txt2img, img2img, run_extras, run_pnginfo):
+def visit(x, func, path=""):
+ if hasattr(x, 'children'):
+ for c in x.children:
+ visit(c, func, path)
+ elif x.label is not None:
+ func(path + "/" + str(x.label), x)
+
+def create_ui(txt2img, img2img, run_extras, run_pnginfo):
with gr.Blocks(analytics_enabled=False) as txt2img_interface:
with gr.Row():
prompt = gr.Textbox(label="Prompt", elem_id="txt2img_prompt", show_label=False, placeholder="Prompt", lines=1)
@@ -271,7 +278,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): with gr.Group():
custom_inputs = modules.scripts.scripts_img2img.setup_ui(is_img2img=True)
-
with gr.Column(variant='panel'):
with gr.Group():
img2img_gallery = gr.Gallery(label='Output', elem_id='img2img_gallery')
@@ -517,6 +523,46 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): css=css,
)
+ ui_config_file = os.path.join(modules.paths.script_path, 'ui-config.json')
+ ui_settings = {}
+ settings_count = len(ui_settings)
+ error_loading = False
+
+ try:
+ if os.path.exists(ui_config_file):
+ with open(ui_config_file, "r", encoding="utf8") as file:
+ ui_settings = json.load(file)
+ except Exception:
+ error_loading = True
+ print("Error loading settings:", file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+
+ def loadsave(path, x):
+ def apply_field(obj, field):
+ key = path + "/" + field
+
+ saved_value = ui_settings.get(key, None)
+ if saved_value is None:
+ ui_settings[key] = getattr(obj, field)
+ else:
+ setattr(obj, field, saved_value)
+
+ if type(x) == gr.Slider:
+ apply_field(x, 'value')
+ apply_field(x, 'minimum')
+ apply_field(x, 'maximum')
+ apply_field(x, 'step')
+
+ if type(x) == gr.Radio:
+ apply_field(x, 'value')
+
+ visit(txt2img_interface, loadsave, "txt2img")
+ visit(img2img_interface, loadsave, "img2img")
+
+ if not error_loading and (not os.path.exists(ui_config_file) or settings_count != len(ui_settings)):
+ with open(ui_config_file, "w", encoding="utf8") as file:
+ json.dump(ui_settings, file, indent=4)
+
return demo
|