From 2ce27728f6433911274efa67856315d22df56629 Mon Sep 17 00:00:00 2001 From: winterspringsummer Date: Sun, 16 Oct 2022 13:50:55 +0900 Subject: added extras batch work from directory --- modules/ui.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index b867d40f..08fa72c6 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1016,6 +1016,15 @@ def create_ui(wrap_gradio_gpu_call): with gr.TabItem('Batch Process'): image_batch = gr.File(label="Batch Process", file_count="multiple", interactive=True, type="file") + with gr.TabItem('Batch from Directory'): + extras_batch_input_dir = gr.Textbox(label="Input directory", **shared.hide_dirs, + placeholder="A directory on the same machine where the server is running." + ) + extras_batch_output_dir = gr.Textbox(label="Output directory", **shared.hide_dirs, + placeholder="Leave blank to save images to the default path." + ) + show_extras_results = gr.Checkbox(label='Show result images', value=True) + with gr.Tabs(elem_id="extras_resize_mode"): with gr.TabItem('Scale by'): upscaling_resize = gr.Slider(minimum=1.0, maximum=4.0, step=0.05, label="Resize", value=2) @@ -1060,6 +1069,9 @@ def create_ui(wrap_gradio_gpu_call): dummy_component, extras_image, image_batch, + extras_batch_input_dir, + extras_batch_output_dir, + show_extras_results, gfpgan_visibility, codeformer_visibility, codeformer_weight, -- cgit v1.2.3 From 3395ba493f93214cf037d084d45693a37610bd85 Mon Sep 17 00:00:00 2001 From: ddPn08 Date: Sun, 16 Oct 2022 09:24:01 +0900 Subject: Allow specifying the region of ngrok. --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 08fa72c6..5c0eaf73 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -56,7 +56,7 @@ if not cmd_opts.share and not cmd_opts.listen: if cmd_opts.ngrok != None: import modules.ngrok as ngrok print('ngrok authtoken detected, trying to connect...') - ngrok.connect(cmd_opts.ngrok, cmd_opts.port if cmd_opts.port != None else 7860) + ngrok.connect(cmd_opts.ngrok, cmd_opts.port if cmd_opts.port != None else 7860, cmd_opts.ngrok_region) def gr_show(visible=True): -- cgit v1.2.3 From 20bf99052a9d50b5f99d199f4c449ef1ddd6e3cb Mon Sep 17 00:00:00 2001 From: CookieHCl Date: Sun, 16 Oct 2022 04:47:03 +0900 Subject: Make style configurable in ui-config.json --- modules/ui.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 5c0eaf73..78096f27 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -508,9 +508,11 @@ def create_toprow(is_img2img): with gr.Row(): with gr.Column(scale=1, elem_id="style_pos_col"): prompt_style = gr.Dropdown(label="Style 1", elem_id=f"{id_part}_style_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys()))) + prompt_style.save_to_config = True with gr.Column(scale=1, elem_id="style_neg_col"): prompt_style2 = gr.Dropdown(label="Style 2", elem_id=f"{id_part}_style2_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys()))) + prompt_style2.save_to_config = True return prompt, roll, prompt_style, negative_prompt, prompt_style2, submit, button_interrogate, button_deepbooru, prompt_style_apply, save_style, paste, token_counter, token_button @@ -1739,6 +1741,11 @@ Requested path was: {f} if type(x) == gr.Number: apply_field(x, 'value') + # Since there are many dropdowns that shouldn't be saved, + # we only mark dropdowns that should be saved. + if type(x) == gr.Dropdown and getattr(x, 'save_to_config', False): + apply_field(x, 'value') + visit(txt2img_interface, loadsave, "txt2img") visit(img2img_interface, loadsave, "img2img") visit(extras_interface, loadsave, "extras") -- cgit v1.2.3 From b65a3101ce82b42b4ccc525044548e66cc44ae4a Mon Sep 17 00:00:00 2001 From: CookieHCl Date: Sun, 16 Oct 2022 04:54:53 +0900 Subject: Use default value when dropdown ui setting is bad Default value is the first value of selectables. Particually, None in styles. --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 78096f27..c8e68bd6 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1744,7 +1744,7 @@ Requested path was: {f} # Since there are many dropdowns that shouldn't be saved, # we only mark dropdowns that should be saved. if type(x) == gr.Dropdown and getattr(x, 'save_to_config', False): - apply_field(x, 'value') + apply_field(x, 'value', lambda val: val in x.choices) visit(txt2img_interface, loadsave, "txt2img") visit(img2img_interface, loadsave, "img2img") -- cgit v1.2.3 From 9258a33e3755c76922cd47a03cd59419b6426304 Mon Sep 17 00:00:00 2001 From: CookieHCl Date: Sun, 16 Oct 2022 05:09:11 +0900 Subject: Warn when user uses bad ui setting --- modules/ui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index c8e68bd6..10bdf121 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1717,7 +1717,9 @@ Requested path was: {f} saved_value = ui_settings.get(key, None) if saved_value is None: ui_settings[key] = getattr(obj, field) - elif condition is None or condition(saved_value): + elif condition and not condition(saved_value): + print(f'Warning: Bad ui setting value: {key}: {saved_value}; Default value "{getattr(obj, field)}" will be used instead.') + else: setattr(obj, field, saved_value) if type(x) in [gr.Slider, gr.Radio, gr.Checkbox, gr.Textbox, gr.Number] and x.visible: -- cgit v1.2.3 From 36a0ba357ab0742c3c4a28437b68fb29a235afbe Mon Sep 17 00:00:00 2001 From: Junpeng Qiu Date: Sat, 15 Oct 2022 21:42:52 -0700 Subject: Added Refresh Button to embedding and hypernetwork names in Train Tab Problem everytime I modified pt files in embedding_dir or hypernetwork_dir, I need to restart webui to have the new files shown in the dropdown of Train Tab Solution refactored create_refresh_button out of create_setting_component so we can use this method to create button next to gr.Dropdowns of embedding name and hypernetworks Extra Modification hypernetwork pt are now sorted in alphabetic order --- modules/ui.py | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 10bdf121..ee3d0248 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -568,6 +568,24 @@ def create_ui(wrap_gradio_gpu_call): import modules.img2img import modules.txt2img + def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id): + def refresh(): + refresh_method() + args = refreshed_args() if callable(refreshed_args) else refreshed_args + + for k, v in args.items(): + setattr(refresh_component, k, v) + + return gr.update(**(args or {})) + + refresh_button = gr.Button(value=refresh_symbol, elem_id=elem_id) + refresh_button.click( + fn = refresh, + inputs = [], + outputs = [refresh_component] + ) + return refresh_button + with gr.Blocks(analytics_enabled=False) as txt2img_interface: txt2img_prompt, roll, txt2img_prompt_style, txt2img_negative_prompt, txt2img_prompt_style2, submit, _, _, txt2img_prompt_style_apply, txt2img_save_style, txt2img_paste, token_counter, token_button = create_toprow(is_img2img=False) dummy_component = gr.Label(visible=False) @@ -1205,8 +1223,12 @@ def create_ui(wrap_gradio_gpu_call): with gr.Tab(label="Train"): gr.HTML(value="

Train an embedding; must specify a directory with a set of 1:1 ratio images

") - train_embedding_name = gr.Dropdown(label='Embedding', choices=sorted(sd_hijack.model_hijack.embedding_db.word_embeddings.keys())) - train_hypernetwork_name = gr.Dropdown(label='Hypernetwork', choices=[x for x in shared.hypernetworks.keys()]) + with gr.Row(): + train_embedding_name = gr.Dropdown(label='Embedding', choices=sorted(sd_hijack.model_hijack.embedding_db.word_embeddings.keys())) + create_refresh_button(train_embedding_name, sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings, lambda: {"choices": sorted(sd_hijack.model_hijack.embedding_db.word_embeddings.keys())}, "refresh_train_embedding_name") + with gr.Row(): + train_hypernetwork_name = gr.Dropdown(label='Hypernetwork', choices=[x for x in shared.hypernetworks.keys()]) + create_refresh_button(train_hypernetwork_name, shared.reload_hypernetworks, lambda: {"choices": sorted([x for x in shared.hypernetworks.keys()])}, "refresh_train_hypernetwork_name") learn_rate = gr.Textbox(label='Learning rate', placeholder="Learning rate", value="0.005") batch_size = gr.Number(label='Batch size', value=1, precision=0) dataset_directory = gr.Textbox(label='Dataset directory', placeholder="Path to directory with input images") @@ -1357,26 +1379,11 @@ def create_ui(wrap_gradio_gpu_call): if info.refresh is not None: if is_quicksettings: res = comp(label=info.label, value=fun, **(args or {})) - refresh_button = gr.Button(value=refresh_symbol, elem_id="refresh_"+key) + refresh_button = create_refresh_button(res, info.refresh, info.component_args, "refresh_" + key) else: with gr.Row(variant="compact"): res = comp(label=info.label, value=fun, **(args or {})) - refresh_button = gr.Button(value=refresh_symbol, elem_id="refresh_" + key) - - def refresh(): - info.refresh() - refreshed_args = info.component_args() if callable(info.component_args) else info.component_args - - for k, v in refreshed_args.items(): - setattr(res, k, v) - - return gr.update(**(refreshed_args or {})) - - refresh_button.click( - fn=refresh, - inputs=[], - outputs=[res], - ) + refresh_button = create_refresh_button(res, info.refresh, info.component_args, "refresh_" + key) else: res = comp(label=info.label, value=fun, **(args or {})) -- cgit v1.2.3