From 1b3093fe3aedb20aa8d505ceeea7900ac592e6fe Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Thu, 10 Aug 2023 15:58:53 +0300 Subject: fix --use-textbox-seed --- modules/ui_loadsave.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules/ui_loadsave.py') diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index 0052a5cc..99d763e1 100644 --- a/modules/ui_loadsave.py +++ b/modules/ui_loadsave.py @@ -8,7 +8,7 @@ from modules.ui_components import ToolButton class UiLoadsave: - """allows saving and restorig default values for gradio components""" + """allows saving and restoring default values for gradio components""" def __init__(self, filename): self.filename = filename @@ -48,6 +48,9 @@ class UiLoadsave: elif condition and not condition(saved_value): pass else: + if isinstance(x, gr.Textbox) and field == 'value': # due to an undersirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies + saved_value = str(saved_value) + setattr(obj, field, saved_value) if init_field is not None: init_field(saved_value) -- cgit v1.2.3 From b13806c15065bd9a91edef2b8516c461ce585361 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Thu, 10 Aug 2023 16:15:34 +0300 Subject: fix a bug preventing normal operation if a string is added to a gr.Number component via ui-config.json --- modules/ui_loadsave.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/ui_loadsave.py') diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index 99d763e1..ef6b0154 100644 --- a/modules/ui_loadsave.py +++ b/modules/ui_loadsave.py @@ -50,6 +50,8 @@ class UiLoadsave: else: if isinstance(x, gr.Textbox) and field == 'value': # due to an undersirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies saved_value = str(saved_value) + elif isinstance(x, gr.Number) and field == 'value': + saved_value = float(saved_value) setattr(obj, field, saved_value) if init_field is not None: -- cgit v1.2.3 From 4412398c4b40f0dd3a1692f65141374770fbc3da Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:44:33 +0900 Subject: catch float ValueError default -1 --- modules/ui_loadsave.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules/ui_loadsave.py') diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index ef6b0154..a96c71b2 100644 --- a/modules/ui_loadsave.py +++ b/modules/ui_loadsave.py @@ -51,7 +51,10 @@ class UiLoadsave: if isinstance(x, gr.Textbox) and field == 'value': # due to an undersirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies saved_value = str(saved_value) elif isinstance(x, gr.Number) and field == 'value': - saved_value = float(saved_value) + try: + saved_value = float(saved_value) + except ValueError: + saved_value = -1 setattr(obj, field, saved_value) if init_field is not None: -- cgit v1.2.3 From a75d756a6fc3a9d66d3c1601d5b8aafcbcd57bde Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Thu, 10 Aug 2023 23:43:55 +0900 Subject: use default value if value error --- modules/ui_loadsave.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/ui_loadsave.py') diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index a96c71b2..9a40cf4f 100644 --- a/modules/ui_loadsave.py +++ b/modules/ui_loadsave.py @@ -48,13 +48,13 @@ class UiLoadsave: elif condition and not condition(saved_value): pass else: - if isinstance(x, gr.Textbox) and field == 'value': # due to an undersirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies + if isinstance(x, gr.Textbox) and field == 'value': # due to an undesirable behavior of gr.Textbox, if you give it an int value instead of str, everything dies saved_value = str(saved_value) elif isinstance(x, gr.Number) and field == 'value': try: saved_value = float(saved_value) except ValueError: - saved_value = -1 + return setattr(obj, field, saved_value) if init_field is not None: -- cgit v1.2.3 From c8c73eae5934ac4dec717d40d624fed613cbd19a Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Thu, 24 Aug 2023 22:03:24 +0300 Subject: fix incorrect save/display of new values in Defaults page in settings --- modules/ui_loadsave.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'modules/ui_loadsave.py') diff --git a/modules/ui_loadsave.py b/modules/ui_loadsave.py index 9a40cf4f..ec8fa8e8 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 -- cgit v1.2.3