Skip to content

Commit

Permalink
Functional restore defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesGaessler committed Sep 1, 2022
1 parent 14acb29 commit 2fb1789
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
9 changes: 5 additions & 4 deletions frontend/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x, txt2img_defaul
'k_euler', 'k_heun', 'k_lms'],
value=txt2img_defaults['sampler_name'])
txt2img_settings = gr.Dropdown(label='Load settings...',
choices=['Program defaults', 'Config', 'From clipboard',
'From file...'],
choices=['Defaults', 'From clipboard', 'From file...'],
value='Config')
with gr.Tabs():
with gr.TabItem('Simple'):
Expand Down Expand Up @@ -123,11 +122,13 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x, txt2img_defaul
txt2img_settings_elements = [
txt2img_prompt, txt2img_steps, txt2img_sampling, txt2img_toggles, txt2img_realesrgan_model_name,
txt2img_ddim_eta, txt2img_batch_count, txt2img_batch_size, txt2img_cfg, txt2img_seed,
txt2img_height, txt2img_width, txt2img_embeddings
txt2img_height, txt2img_width, txt2img_embeddings, txt2img_variant_amount, txt2img_variant_seed
]
txt2img_settings_checkboxgroup_info = [(3, txt2img_toggles.choices)]
txt2img_settings.change(
fn=lambda *x: uifn.load_settings(*x, txt2img_settings_checkboxgroup_info),
fn=lambda *x: uifn.load_settings(
*x, uifn.LOAD_SETTINGS_TXT2IMG_NAMES, txt2img_defaults, txt2img_settings_checkboxgroup_info
),
inputs=txt2img_settings_elements + [txt2img_settings],
outputs=txt2img_settings_elements
)
Expand Down
31 changes: 26 additions & 5 deletions frontend/ui_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import re
import sys
import gradio as gr
from PIL import Image, ImageFont, ImageDraw, ImageFilter, ImageOps
from io import BytesIO
import base64
import re

LOAD_SETTINGS_TXT2IMG_NAMES = [
"prompt", "ddim_steps", "sampler_name", "toggles", "realesrgan_model_name", "ddim_eta",
"n_iter", "batch_size", "cfg_scale", "seed", "height", "width", "fp", "variant_amount", "variant_seed"
]

def change_image_editor_mode(choice, cropped_image, resize_mode, width, height):
if choice == "Mask":
Expand Down Expand Up @@ -112,11 +117,27 @@ def update_dimensions_info(width, height):
return f"Aspect ratio: {round(width / height, 5)}\nTotal pixel count: {pixel_count_formated}"

def load_settings(*values):
print(values)
new_settings, checkboxgroup_info = values[-2:]
values = list(values[:-2])
new_settings, key_names, defaults, checkboxgroup_info = values[-4:]
values = list(values[:-4])

if new_settings == "Defaults":
new_settings = defaults
elif new_settings == "From file...":
new_settings = {}
else:
raise AssertionError()

skipped_settings = {}
for key in new_settings.keys():
if key in key_names:
values[key_names.index(key)] = new_settings[key]
else:
skipped_settings[key] = new_settings[key]
if skipped_settings:
print(f"Settings could not be applied: {skipped_settings}", file=sys.stderr)

# Convert lists of checkbox indices to lists of checkbox labels:
for (cbg_index, cbg_choices) in checkboxgroup_info:
values[cbg_index] = [cbg_choices[i] for i in values[cbg_index]]
# values[cbg_index] = []
print(values)

return values

0 comments on commit 2fb1789

Please sign in to comment.