Skip to content

Commit

Permalink
fix: webui more robust handling of missing config values. (#140)
Browse files Browse the repository at this point in the history
If new config items have been added to the webui, but an existing worker doesn't have them in their existing config file when the webui starts, we need to provide some sort of default value.
  • Loading branch information
jug-dev authored Mar 26, 2023
1 parent 312e55a commit fcab571
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DotDict(dict):
def __getattr__(self, attr):
if attr in self:
return self[attr]
return ""
return None

def __setattr__(self, attr, value):
self[attr] = value
Expand All @@ -29,6 +29,10 @@ def __delattr__(self, attr):
else:
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{attr}'")

def default(self, attr, value):
if attr not in self:
self[attr] = value


class WebUI:

Expand Down Expand Up @@ -385,20 +389,23 @@ def initialise(self):
models_to_load_individual.append(model)

existing_priority_usernames = ""
config.default("priority_usernames", [])
for item in config.priority_usernames:
existing_priority_usernames += item
existing_priority_usernames += ","
if len(existing_priority_usernames) > 0 and existing_priority_usernames[-1] == ",":
existing_priority_usernames = existing_priority_usernames[:-1]

existing_blacklist = ""
config.default("blacklist", [])
for item in config.blacklist:
existing_blacklist += item
existing_blacklist += ","
if len(existing_blacklist) > 0 and existing_blacklist[-1] == ",":
existing_blacklist = existing_blacklist[:-1]

existing_censorlist = ""
config.default("censorlist", [])
for item in config.censorlist:
existing_censorlist += item
existing_censorlist += ","
Expand Down Expand Up @@ -430,6 +437,7 @@ def initialise(self):
info=self._info("api_key"),
)
slider_desc = gr.Markdown("Maximum Image Size")
config.default("max_power", 8)
max_power = gr.Slider(
2,
128,
Expand All @@ -449,26 +457,31 @@ def initialise(self):

with gr.Tab("Enable Features"):
with gr.Column():
config.default("allow_img2img", True)
allow_img2img = gr.Checkbox(
label=self._label("allow_img2img"),
value=config.allow_img2img,
info=self._info("allow_img2img"),
)
config.default("allow_painting", True)
allow_painting = gr.Checkbox(
label=self._label("allow_painting"),
value=config.allow_painting,
info=self._info("allow_painting"),
)
config.default("allow_post_processing", True)
allow_post_processing = gr.Checkbox(
label=self._label("allow_post_processing"),
value=config.allow_post_processing,
info=self._info("allow_post_processing"),
)
config.default("allow_controlnet", True)
allow_controlnet = gr.Checkbox(
label=self._label("allow_controlnet"),
value=config.allow_controlnet,
info=self._info("allow_controlnet"),
)
config.default("forms", [])
forms = gr.CheckboxGroup(
label=self._label("forms"),
choices=["caption", "nsfw", "interrogation", "post-process"],
Expand Down Expand Up @@ -522,6 +535,7 @@ def initialise(self):

with gr.Tab("Models to Skip"):
with gr.Column():
config.default("models_to_skip", [])
models_to_skip = gr.CheckboxGroup(
choices=model_list,
label=self._label("models_to_skip"),
Expand All @@ -531,43 +545,51 @@ def initialise(self):

with gr.Tab("Model Management"):
with gr.Column():
config.default("always_download", True)
always_download = gr.Checkbox(
label=self._label("always_download"),
value=config.always_download,
info=self._info("always_download"),
)
config.default("enable_model_cache", False)
enable_model_cache = gr.Checkbox(
label=self._label("enable_model_cache"),
value=config.enable_model_cache,
info=self._info("enable_model_cache"),
)
config.default("disable_voodoo", False)
disable_voodoo = gr.Checkbox(
label=self._label("disable_voodoo"),
value=config.disable_voodoo,
info=self._info("disable_voodoo"),
)
config.default("max_models_to_download", 10)
max_models_to_download = gr.Number(
label=self._label("max_models_to_download"),
value=config.max_models_to_download,
precision=0,
info=self._info("max_models_to_download"),
)
config.default("dynamic_models", True)
dynamic_models = gr.Checkbox(
label=self._label("dynamic_models"),
value=config.dynamic_models,
info=self._info("dynamic_models"),
)
config.default("number_of_dynamic_models", 3)
number_of_dynamic_models = gr.Number(
label=self._label("number_of_dynamic_models"),
value=config.number_of_dynamic_models,
precision=0,
info=self._info("number_of_dynamic_models"),
)
config.default("nataili_cache_home", "./")
nataili_cache_home = gr.Textbox(
label=self._label("nataili_cache_home"),
value=config.nataili_cache_home,
info=self._info("nataili_cache_home"),
)
config.default("ray_temp_dir", "./ray")
ray_temp_dir = gr.Textbox(
label=self._label("ray_temp_dir"),
value=config.ray_temp_dir,
Expand All @@ -576,11 +598,13 @@ def initialise(self):

with gr.Tab("Security"):
with gr.Column():
config.default("allow_unsafe_ip", False)
allow_unsafe_ip = gr.Checkbox(
label=self._label("allow_unsafe_ip"),
value=config.allow_unsafe_ip,
info=self._info("allow_unsafe_ip"),
)
config.default("require_upfront_kudos", False)
require_upfront_kudos = gr.Checkbox(
label=self._label("require_upfront_kudos"),
value=config.require_upfront_kudos,
Expand All @@ -596,11 +620,13 @@ def initialise(self):
value=existing_censorlist,
info=self._info("censorlist"),
)
config.default("nsfw", True)
nsfw = gr.Checkbox(
label=self._label("nsfw"),
value=config.nsfw,
info=self._info("nsfw"),
)
config.default("censor_nsfw", False)
censor_nsfw = gr.Checkbox(
label=self._label("censor_nsfw"),
value=config.censor_nsfw,
Expand All @@ -609,6 +635,7 @@ def initialise(self):

with gr.Tab("Performance"):
with gr.Column():
config.default("threads", 1)
max_threads = gr.Slider(
1,
8,
Expand All @@ -617,6 +644,7 @@ def initialise(self):
value=config.max_threads,
info=self._info("threads"),
)
config.default("queue_size", 1)
queue_size = gr.Slider(
0,
2,
Expand All @@ -628,21 +656,25 @@ def initialise(self):

with gr.Tab("Advanced"):
with gr.Column():
config.default("enable_terminal_ui", False)
enable_terminal_ui = gr.Checkbox(
label=self._label("enable_terminal_ui"),
value=config.enable_terminal_ui,
info=self._info("enable_terminal_ui"),
)
config.default("horde_url", "https://stablehorde.net/")
horde_url = gr.Textbox(
label=self._label("horde_url"),
value=config.horde_url,
info=self._info("horde_url"),
)
config.default("low_vram_mode", True)
low_vram_mode = gr.Checkbox(
label=self._label("low_vram_mode"),
value=config.low_vram_mode,
info=self._info("low_vram_mode"),
)
config.default("stats_output_frequency", 30)
stats_output_frequency = gr.Number(
label=self._label("stats_output_frequency"),
value=config.stats_output_frequency,
Expand Down

0 comments on commit fcab571

Please sign in to comment.