From c8c73eae5934ac4dec717d40d624fed613cbd19a Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Thu, 24 Aug 2023 22:03:24 +0300 Subject: [PATCH] fix incorrect save/display of new values in Defaults page in settings --- modules/ui_loadsave.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index 9a40cf4fc..ec8fa8e89 100644 --- a/modules/ui_loadsave.py +++ b/modules/ui_loadsave.py @@ -7,6 +7,10 @@ from modules import errors from modules.ui_components import ToolButton +def radio_choices(comp): # gradio 3.41 changes choices from list of values to list of pairs + return [x[0] if isinstance(x, tuple) else x for x in getattr(comp, 'choices', [])] + + class UiLoadsave: """allows saving and restoring default values for gradio components""" @@ -28,6 +32,8 @@ class UiLoadsave: self.error_loading = True errors.display(e, "loading settings") + + def add_component(self, path, x): """adds component to the registry of tracked components""" @@ -73,7 +79,7 @@ class UiLoadsave: apply_field(x, 'step') if type(x) == gr.Radio: - apply_field(x, 'value', lambda val: val in x.choices) + apply_field(x, 'value', lambda val: val in radio_choices(x)) if type(x) == gr.Checkbox: apply_field(x, 'value') @@ -86,10 +92,11 @@ class UiLoadsave: if type(x) == gr.Dropdown: def check_dropdown(val): + choices = radio_choices(x) if getattr(x, 'multiselect', False): - return all(value in x.choices for value in val) + return all(value in choices for value in val) else: - return val in x.choices + return val in choices apply_field(x, 'value', check_dropdown, getattr(x, 'init_field', None)) @@ -146,12 +153,14 @@ class UiLoadsave: for (path, component), new_value in zip(self.component_mapping.items(), values): old_value = current_ui_settings.get(path) - choices = getattr(component, 'choices', None) + choices = radio_choices(component) if isinstance(new_value, int) and choices: if new_value >= len(choices): continue new_value = choices[new_value] + if isinstance(new_value, tuple): + new_value = new_value[0] if new_value == old_value: continue