From 26a77902557b6ed7a68343d2864ba64285376ce2 Mon Sep 17 00:00:00 2001 From: ateeb Date: Sun, 16 Jun 2024 08:23:36 +0500 Subject: [PATCH 01/32] First try UI --- webui.py | 907 ++++++------------------------------------------------- 1 file changed, 90 insertions(+), 817 deletions(-) diff --git a/webui.py b/webui.py index 97f102c04..fb865c08a 100644 --- a/webui.py +++ b/webui.py @@ -4,839 +4,112 @@ import json import time import shared -import modules.config +import modules.config as config import fooocus_version -import modules.html +import modules.html as html import modules.async_worker as worker import modules.constants as constants import modules.flags as flags import modules.gradio_hijack as grh import modules.style_sorter as style_sorter -import modules.meta_parser +import modules.meta_parser as meta_parser from modules.rembg import rembg_run import args_manager import copy import launch - -from modules.sdxl_styles import legal_style_names -from modules.private_logger import get_current_html_path -from modules.ui_gradio_extensions import reload_javascript -from modules.auth import auth_enabled, check_auth -from modules.util import is_json - -PHOTOPEA_MAIN_URL = "https://www.photopea.com/" -PHOTOPEA_IFRAME_ID = "webui-photopea-iframe" -PHOTOPEA_IFRAME_HEIGHT = 684 -PHOTOPEA_IFRAME_WIDTH = "100%" -PHOTOPEA_IFRAME_LOADED_EVENT = "onPhotopeaLoaded" - - -def get_photopea_url_params(): - return "#%7B%22resources%22:%5B%22data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAQMAAADOtka5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRF////p8QbyAAAADZJREFUeJztwQEBAAAAgiD/r25IQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfBuCAAAB0niJ8AAAAABJRU5ErkJggg==%22%5D%7D" - +from SegBody import segment_body def get_task(*args): args = list(args) args.pop(0) - return worker.AsyncTask(args=args) -def generate_clicked(task): - import ldm_patched.modules.model_management as model_management - - with model_management.interrupt_processing_mutex: - model_management.interrupt_processing = False - # outputs=[progress_html, progress_window, progress_gallery, gallery] - execution_start_time = time.perf_counter() - finished = False - - yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ - gr.update(visible=True, value=None), \ - gr.update(visible=False, value=None), \ - gr.update(visible=False) - - worker.async_tasks.append(task) - - while not finished: - time.sleep(0.01) - if len(task.yields) > 0: - flag, product = task.yields.pop(0) - if flag == 'preview': - - # help bad internet connection by skipping duplicated preview - if len(task.yields) > 0: # if we have the next item - if task.yields[0][0] == 'preview': # if the next item is also a preview - # print('Skipped one preview for better internet connection.') - continue - - percentage, title, image = product - yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \ - gr.update(visible=True, value=image) if image is not None else gr.update(), \ - gr.update(), \ - gr.update(visible=False) - if flag == 'results': - yield gr.update(visible=True), \ - gr.update(visible=True), \ - gr.update(visible=True, value=product), \ - gr.update(visible=False) - if flag == 'finish': - yield gr.update(visible=False), \ - gr.update(visible=False), \ - gr.update(visible=False), \ - gr.update(visible=True, value=product) - finished = True - - # delete Fooocus temp images, only keep gradio temp images - if args_manager.args.disable_image_log: - for filepath in product: - os.remove(filepath) - - execution_time = time.perf_counter() - execution_start_time - global time_taken - time_taken = f"Total time: {execution_time:.2f} seconds" - print(time_taken) - return - - -reload_javascript() - -title = f'DeFooocus {fooocus_version.version}' - -if isinstance(args_manager.args.preset, str): - title += ' ' + args_manager.args.preset - -shared.gradio_root = gr.Blocks( - title=title, - css=modules.html.css, - theme="ehristoforu/Indigo_Theme").queue() - -with shared.gradio_root: - currentTask = gr.State(worker.AsyncTask(args=[])) - with gr.Row(): - with gr.Column(scale=2): - with gr.Tab("Generation"): - with gr.Row(): - progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768, - elem_classes=['main_view']) - progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain', - height=768, visible=False, elem_classes=['main_view', 'image_gallery']) - progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False, - elem_id='progress-bar', elem_classes='progress-bar') - gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768, - elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'], - elem_id='final_gallery') - with gr.Tab("Photopea"): - with gr.Row(): - photopea = gr.HTML( - f"""") + with gr.Tab("Tools"): + for name in load_tools_names(): + url = load_tools_url(name) + with gr.Tab(name): + gr.HTML(f"") with gr.Row(elem_classes='type_row'): with gr.Column(scale=17): - prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt', container=False, autofocus=True, elem_classes='type_row', lines=1024) + prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt', + container=False, autofocus=True, elem_classes='type_row', lines=1024) + default_prompt = modules.config.default_prompt if isinstance(default_prompt, str) and default_prompt != '': shared.gradio_root.load(lambda: default_prompt, outputs=prompt) + with gr.Column(scale=3, min_width=0): generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True) load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False) @@ -167,13 +189,19 @@ def skip_clicked(currentTask): stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever') skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False) - with gr.Row(elem_classes='advanced_check_row'): - input_image_checkbox = gr.Checkbox(label='Input Image', value=True, container=False, elem_classes='min_check', visible=False) - advanced_checkbox = gr.Checkbox(label='Advanced', value=True, container=False, elem_classes='min_check', visible=False) - + input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check') + advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check') + with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): + with gr.TabItem(label='Upscale or Variation') as uov_tab: + with gr.Row(): + with gr.Column(): + uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') + with gr.Column(): + uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) + gr.HTML('\U0001F4D4 Document') with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -189,39 +217,59 @@ def skip_clicked(currentTask): ip_ctrls.append(ip_image) with gr.Column(visible=False) as ad_col: with gr.Row(): - ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=0.85, visible=False) + default_end, default_weight = flags.default_parameters[flags.default_ip] + + ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end) ip_stops.append(ip_stop) ip_ctrls.append(ip_stop) - ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=0.97, visible=False) + + ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight) ip_weights.append(ip_weight) ip_ctrls.append(ip_weight) + ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=flags.default_ip, container=False) ip_types.append(ip_type) ip_ctrls.append(ip_type) + ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False) ip_ad_cols.append(ad_col) ip_advanced = gr.Checkbox(label='Advanced', value=False, container=False) - gr.HTML('* "Image Prompt" is powered by Fooocus Image Mixture Engine (v1.0.1). \U0001F4D4 Document') + gr.HTML('* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1). \U0001F4D4 Document') def ip_advance_checked(x): - return [gr.update(visible=x)] * len(ip_ad_cols) + [flags.default_ip] * len(ip_types) + [0.85] * len(ip_stops) + [0.97] * len(ip_weights) + return [gr.update(visible=x)] * len(ip_ad_cols) + \ + [flags.default_ip] * len(ip_types) + \ + [flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \ + [flags.default_parameters[flags.default_ip][1]] * len(ip_weights) - ip_advanced.change(ip_advance_checked, inputs=ip_advanced, outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, queue=False, show_progress=False) + ip_advanced.change(ip_advance_checked, inputs=ip_advanced, + outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, + queue=False, show_progress=False) with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab: with gr.Row(): with gr.Column(): inpaint_input_image = grh.Image(label='Drag inpaint or outpaint image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas') - inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method', visible=False) + inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method') inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False) - outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction', visible=False) - example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False) + outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction') + example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, + label='Additional Prompt Quick List', + components=[inpaint_additional_prompt], + visible=False) gr.HTML('* Powered by Fooocus Inpaint Engine \U0001F4D4 Document') example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False) - with gr.Column(visible=True) as inpaint_mask_generation_col: - inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', height=500) - inpaint_mask_model = gr.Dropdown(label='Mask generation model', choices=flags.inpaint_mask_models, value=modules.config.default_inpaint_mask_model) - inpaint_mask_cloth_category = gr.Dropdown(label='Cloth category', choices=flags.inpaint_mask_cloth_category, value=modules.config.default_inpaint_mask_cloth_category, visible=False) + + with gr.Column(visible=False) as inpaint_mask_generation_col: + inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', + height=500) + inpaint_mask_model = gr.Dropdown(label='Mask generation model', + choices=flags.inpaint_mask_models, + value=modules.config.default_inpaint_mask_model) + inpaint_mask_cloth_category = gr.Dropdown(label='Cloth category', + choices=flags.inpaint_mask_cloth_category, + value=modules.config.default_inpaint_mask_cloth_category, + visible=False) inpaint_mask_sam_prompt_text = gr.Textbox(label='Segmentation prompt', value='', visible=False) with gr.Accordion("Advanced options", visible=False, open=False) as inpaint_mask_advanced_options: inpaint_mask_sam_model = gr.Dropdown(label='SAM model', choices=flags.inpaint_mask_sam_model, value=modules.config.default_inpaint_mask_sam_model) @@ -232,6 +280,7 @@ def ip_advance_checked(x): def generate_mask(image, mask_model, cloth_category, sam_prompt_text, sam_model, sam_quant, box_threshold, text_threshold): from extras.inpaint_mask import generate_mask_from_image + extras = {} if mask_model == 'u2net_cloth_seg': extras['cloth_category'] = cloth_category @@ -241,12 +290,38 @@ def generate_mask(image, mask_model, cloth_category, sam_prompt_text, sam_model, extras['sam_quant'] = sam_quant extras['box_threshold'] = box_threshold extras['text_threshold'] = text_threshold - return generate_mask_from_image(image, mask_model, extras) - generate_mask_button.click(fn=generate_mask, inputs=[inpaint_input_image, inpaint_mask_model, inpaint_mask_cloth_category, inpaint_mask_sam_prompt_text, inpaint_mask_sam_model, inpaint_mask_sam_quant, inpaint_mask_box_threshold, inpaint_mask_text_threshold], outputs=inpaint_mask_image, show_progress=True, queue=True) - inpaint_mask_model.change(lambda x: [gr.update(visible=x == 'u2net_cloth_seg'), gr.update(visible=x == 'sam'), gr.update(visible=x == 'sam')], inputs=inpaint_mask_model, outputs=[inpaint_mask_cloth_category, inpaint_mask_sam_prompt_text, inpaint_mask_advanced_options], queue=False, show_progress=False) + return generate_mask_from_image(image, mask_model, extras) - with gr.TabItem(label='Metadata', visible=False) as load_tab: + generate_mask_button.click(fn=generate_mask, + inputs=[ + inpaint_input_image, inpaint_mask_model, + inpaint_mask_cloth_category, + inpaint_mask_sam_prompt_text, + inpaint_mask_sam_model, + inpaint_mask_sam_quant, + inpaint_mask_box_threshold, + inpaint_mask_text_threshold + ], + outputs=inpaint_mask_image, show_progress=True, queue=True) + + inpaint_mask_model.change(lambda x: [gr.update(visible=x == 'u2net_cloth_seg'), gr.update(visible=x == 'sam'), gr.update(visible=x == 'sam')], + inputs=inpaint_mask_model, + outputs=[inpaint_mask_cloth_category, inpaint_mask_sam_prompt_text, inpaint_mask_advanced_options], + queue=False, show_progress=False) + + with gr.TabItem(label='Describe') as desc_tab: + with gr.Row(): + with gr.Column(): + desc_input_image = grh.Image(label='Drag any image to here', source='upload', type='numpy') + with gr.Column(): + desc_method = gr.Radio( + label='Content Type', + choices=[flags.desc_type_photo, flags.desc_type_anime], + value=flags.desc_type_photo) + desc_btn = gr.Button(value='Describe this Image into Prompt') + gr.HTML('\U0001F4D4 Document') + with gr.TabItem(label='Metadata') as load_tab: with gr.Column(): metadata_input_image = grh.Image(label='Drag any image generated by Fooocus here', source='upload', type='filepath') metadata_json = gr.JSON(label='Metadata') @@ -254,19 +329,24 @@ def generate_mask(image, mask_model, cloth_category, sam_prompt_text, sam_model, def trigger_metadata_preview(filepath): parameters, metadata_scheme = modules.meta_parser.read_info_from_image(filepath) + results = {} if parameters is not None: results['parameters'] = parameters + if isinstance(metadata_scheme, flags.MetadataScheme): results['metadata_scheme'] = metadata_scheme.value + return results - metadata_input_image.upload(trigger_metadata_preview, inputs=metadata_input_image, outputs=metadata_json, queue=False, show_progress=True) + metadata_input_image.upload(trigger_metadata_preview, inputs=metadata_input_image, + outputs=metadata_json, queue=False, show_progress=True) switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}" down_js = "() => {viewer_to_bottom();}" - input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox, outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js) + input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox, + outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js) ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) current_tab = gr.Textbox(value='uov', visible=False) @@ -277,13 +357,47 @@ def trigger_metadata_preview(filepath): with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column: with gr.Tab(label='Settings'): - performance_selection = gr.Radio(label='Performance', choices=modules.flags.performance_selections, value=modules.config.default_performance, elem_classes='performance_selections') - if not args_manager.args.disable_preset_selection: - preset_selection = gr.Radio(label='Preset', choices=modules.config.available_presets, value=args_manager.args.preset if args_manager.args.preset else "initial", interactive=True) - aspect_ratios_selection = gr.Radio(label='Aspect Ratios', choices=modules.config.available_aspect_ratios, value=modules.config.default_aspect_ratio, info='width × height', elem_classes='aspect_ratios') + with gr.Row(): + performance_selection = gr.Radio(label='Performance', + choices=modules.flags.performance_selections, + value=modules.config.default_performance, + elem_classes='performance_selections') + if not args_manager.args.disable_preset_selection: + preset_selection = gr.Dropdown(label='Preset', + choices=modules.config.available_presets, + value=args_manager.args.preset if args_manager.args.preset else "initial", + interactive=True) + + aspect_ratios_selection = gr.Radio(label='Aspect Ratios', choices=modules.config.available_aspect_ratios, + value=modules.config.default_aspect_ratio, info='width × height', + elem_classes='aspect_ratios') + + with gr.Column(): + sampling_apply = gr.Checkbox(label="Sampling", value=False) + with gr.Row(visible=False) as sampling: + sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, + value=modules.config.default_sampler) + scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, + value=modules.config.default_scheduler) + sampling_apply.change( + fn=lambda x: gr.update(visible=x), + inputs=sampling_apply, + outputs=sampling, + queue=False, + api_name=False, + ) + + image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number) - negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.", info='Describing what you do not want to see.', lines=2, elem_id='negative_prompt', value=modules.config.default_prompt_negative) - translate_prompts = gr.Checkbox(label='Translate Prompts', info='Uses the internet to translate prompts to English.', value=False) + + + negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.", + info='Describing what you do not want to see.', lines=2, + elem_id='negative_prompt', + value=modules.config.default_prompt_negative) + translate_prompts = gr.Checkbox(label='Translate Prompts', + info='Uses the internet to translate prompts to English.', + value=False) seed_random = gr.Checkbox(label='Randomize seed', value=True) image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354 @@ -302,97 +416,245 @@ def refresh_seed(r, seed_string): pass return random.randint(constants.MIN_SEED, constants.MAX_SEED) - seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], queue=False, show_progress=False) + seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], + queue=False, show_progress=False) def update_history_link(): if args_manager.args.disable_image_log: return gr.update(value='') + return gr.update(value=f'\U0001F4DA History Log') history_link = gr.HTML() shared.gradio_root.load(update_history_link, outputs=history_link, queue=False, show_progress=False) with gr.Tab(label='Styles'): - style_sorter.try_load_sorted_styles(style_names=legal_style_names, default_selected=modules.config.default_styles) - style_search_bar = gr.Textbox(show_label=False, container=False, placeholder="\U0001F50E Type here to search styles ...", value="", label='Search Styles') - style_selections = gr.CheckboxGroup(show_label=False, container=False, choices=copy.deepcopy(style_sorter.all_styles), value=copy.deepcopy(modules.config.default_styles), label='Selected Styles', elem_classes=['style_selections']) + style_sorter.try_load_sorted_styles( + style_names=legal_style_names, + default_selected=modules.config.default_styles) + + style_search_bar = gr.Textbox(show_label=False, container=False, + placeholder="\U0001F50E Type here to search styles ...", + value="", + label='Search Styles') + style_selections = gr.CheckboxGroup(show_label=False, container=False, + choices=copy.deepcopy(style_sorter.all_styles), + value=copy.deepcopy(modules.config.default_styles), + label='Selected Styles', + elem_classes=['style_selections']) gradio_receiver_style_selections = gr.Textbox(elem_id='gradio_receiver_style_selections', visible=False) - shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)), outputs=style_selections) - style_search_bar.change(style_sorter.search_styles, inputs=[style_selections, style_search_bar], outputs=style_selections, queue=False, show_progress=False).then(lambda: None, _js='()=>{refresh_style_localization();}') - gradio_receiver_style_selections.input(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False).then(lambda: None, _js='()=>{refresh_style_localization();}') + shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)), + outputs=style_selections) + + style_search_bar.change(style_sorter.search_styles, + inputs=[style_selections, style_search_bar], + outputs=style_selections, + queue=False, + show_progress=False).then( + lambda: None, _js='()=>{refresh_style_localization();}') + + gradio_receiver_style_selections.input(style_sorter.sort_styles, + inputs=style_selections, + outputs=style_selections, + queue=False, + show_progress=False).then( + lambda: None, _js='()=>{refresh_style_localization();}') with gr.Tab(label='Models'): with gr.Group(): with gr.Row(): base_model = gr.Dropdown(label='Base Model (SDXL only)', choices=modules.config.model_filenames, value=modules.config.default_base_model_name, show_label=True) refiner_model = gr.Dropdown(label='Refiner (SDXL or SD 1.5)', choices=['None'] + modules.config.model_filenames, value=modules.config.default_refiner_model_name, show_label=True) - refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001, info='Use 0.4 for SD1.5 realistic models; or 0.667 for SD1.5 anime models; or 0.8 for XL-refiners; or any value for switching two SDXL models.', value=modules.config.default_refiner_switch, visible=modules.config.default_refiner_model_name != 'None') - refiner_model.change(lambda x: gr.update(visible=x != 'None'), inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False) + + refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001, + info='Use 0.4 for SD1.5 realistic models; ' + 'or 0.667 for SD1.5 anime models; ' + 'or 0.8 for XL-refiners; ' + 'or any value for switching two SDXL models.', + value=modules.config.default_refiner_switch, + visible=modules.config.default_refiner_model_name != 'None') + + refiner_model.change(lambda x: gr.update(visible=x != 'None'), + inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False) with gr.Group(): lora_ctrls = [] + for i, (n, v) in enumerate(modules.config.default_loras): with gr.Row(): - lora_model = gr.Dropdown(label=f'LoRA {i + 1}', choices=['None'] + modules.config.lora_filenames, value=n) - lora_weight = gr.Slider(label='Weight', minimum=-2, maximum=2, step=0.01, value=v, elem_classes='lora_weight') + lora_model = gr.Dropdown(label=f'LoRA {i + 1}', + choices=['None'] + modules.config.lora_filenames, value=n) + lora_weight = gr.Slider(label='Weight', minimum=-2, maximum=2, step=0.01, value=v, + elem_classes='lora_weight') lora_ctrls += [lora_model, lora_weight] with gr.Row(): model_refresh = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button') - with gr.Tab(label='Advanced'): - guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01, value=modules.config.default_cfg_scale, info='Higher value means style is cleaner, vivider, and more artistic.') - sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001, value=modules.config.default_sample_sharpness, info='Higher value means image and texture are sharper.') + guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01, + value=modules.config.default_cfg_scale, + info='Higher value means style is cleaner, vivider, and more artistic.') + sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001, + value=modules.config.default_sample_sharpness, + info='Higher value means image and texture are sharper.') gr.HTML('\U0001F4D4 Document') - output_format = gr.Radio(label='Output Format', choices=modules.flags.output_formats, value=modules.config.default_output_format) + output_format = gr.Radio(label='Output Format', + choices=modules.flags.output_formats, + value=modules.config.default_output_format) + + play_notification = gr.Checkbox(label='Play notification after rendering', value=False) + notification_file = 'notification.mp3' + if os.path.exists(notification_file): + notification = gr.State(value=notification_file) + notification_input = gr.Audio(label='Notification', interactive=True, elem_id='audio_notification', visible=False, show_edit_button=False) + + def play_notification_checked(r, notification): + return gr.update(visible=r, value=notification if r else None) - dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False) - with gr.Column(visible=False) as dev_tools: + def notification_input_changed(notification_input, notification): + if notification_input: + notification = notification_input + return notification + + play_notification.change(fn=play_notification_checked, inputs=[play_notification, notification], outputs=[notification_input], queue=False) + notification_input.change(fn=notification_input_changed, inputs=[notification_input, notification], outputs=[notification], queue=False) + + + dev_mode = gr.Checkbox(label='Advanced mode', value=True, container=False) + + with gr.Column(visible=True) as dev_tools: with gr.Tab(label='Debug Tools'): - adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0, step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ') - adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0, step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ') - adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0, step=0.001, value=0.3, info='When to end the guidance from positive/negative ADM. ') - refiner_swap_method = gr.Dropdown(label='Refiner swap method', value=flags.refiner_swap_method, choices=['joint', 'separate', 'vae']) - adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01, value=modules.config.default_cfg_tsnr, info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR (effective when real CFG > mimicked CFG).') - sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, value=modules.config.default_sampler) - scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, value=modules.config.default_scheduler) - generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch', info='(Experimental) This may cause performance problems on some computers and certain internet conditions.', value=False) - overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step', minimum=-1, maximum=200, step=1, value=modules.config.default_overwrite_step, info='Set as -1 to disable. For developer debugging.') - overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step', minimum=-1, maximum=200, step=1, value=modules.config.default_overwrite_switch, info='Set as -1 to disable. For developer debugging.') - overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width', minimum=-1, maximum=2048, step=1, value=-1, info='Set as -1 to disable. For developer debugging. Results will be worse for non-standard numbers that SDXL is not trained on.') - overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height', minimum=-1, maximum=2048, step=1, value=-1, info='Set as -1 to disable. For developer debugging. Results will be worse for non-standard numbers that SDXL is not trained on.') - overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"', minimum=-1, maximum=1.0, step=0.001, value=-1, info='Set as negative number to disable. For developer debugging.') - overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"', minimum=-1, maximum=1.0, step=0.001, value=modules.config.default_overwrite_upscale, info='Set as negative number to disable. For developer debugging.') - disable_preview = gr.Checkbox(label='Disable Preview', value=modules.config.default_black_out_nsfw, interactive=not modules.config.default_black_out_nsfw, info='Disable preview during generation.') - disable_intermediate_results = gr.Checkbox(label='Disable Intermediate Results', value=modules.config.default_performance == 'Extreme Speed', interactive=modules.config.default_performance != 'Extreme Speed', info='Disable intermediate results during generation, only show final gallery.') - black_out_nsfw = gr.Checkbox(label='Black Out NSFW', value=modules.config.default_black_out_nsfw, interactive=not modules.config.default_black_out_nsfw, info='Use black image if NSFW is detected.') - black_out_nsfw.change(lambda x: gr.update(value=x, interactive=not x), inputs=black_out_nsfw, outputs=disable_preview, queue=False, show_progress=False) + adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0, + step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ') + adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0, + step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ') + adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0, + step=0.001, value=0.3, + info='When to end the guidance from positive/negative ADM. ') + + refiner_swap_method = gr.Dropdown(label='Refiner swap method', value=flags.refiner_swap_method, + choices=['joint', 'separate', 'vae']) + + adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01, + value=modules.config.default_cfg_tsnr, + info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR ' + '(effective when real CFG > mimicked CFG).') + ''' + sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, + value=modules.config.default_sampler) + scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, + value=modules.config.default_scheduler) + ''' + generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch', + info='(Experimental) This may cause performance problems on some computers and certain internet conditions.', + value=False) + + overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step', + minimum=-1, maximum=200, step=1, + value=modules.config.default_overwrite_step, + info='Set as -1 to disable. For developer debugging.') + overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step', + minimum=-1, maximum=200, step=1, + value=modules.config.default_overwrite_switch, + info='Set as -1 to disable. For developer debugging.') + overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width', + minimum=-1, maximum=2048, step=1, value=-1, + info='Set as -1 to disable. For developer debugging. ' + 'Results will be worse for non-standard numbers that SDXL is not trained on.') + overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height', + minimum=-1, maximum=2048, step=1, value=-1, + info='Set as -1 to disable. For developer debugging. ' + 'Results will be worse for non-standard numbers that SDXL is not trained on.') + overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"', + minimum=-1, maximum=1.0, step=0.001, value=-1, + info='Set as negative number to disable. For developer debugging.') + overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"', + minimum=-1, maximum=1.0, step=0.001, + value=modules.config.default_overwrite_upscale, + info='Set as negative number to disable. For developer debugging.') + + disable_preview = gr.Checkbox(label='Disable Preview', value=modules.config.default_black_out_nsfw, + interactive=not modules.config.default_black_out_nsfw, + info='Disable preview during generation.') + disable_intermediate_results = gr.Checkbox(label='Disable Intermediate Results', + value=modules.config.default_performance == 'Extreme Speed', + interactive=modules.config.default_performance != 'Extreme Speed', + info='Disable intermediate results during generation, only show final gallery.') + + black_out_nsfw = gr.Checkbox(label='Black Out NSFW', value=modules.config.default_black_out_nsfw, + interactive=not modules.config.default_black_out_nsfw, + info='Use black image if NSFW is detected.') + + black_out_nsfw.change(lambda x: gr.update(value=x, interactive=not x), + inputs=black_out_nsfw, outputs=disable_preview, queue=False, show_progress=False) + if not args_manager.args.disable_metadata: - save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images, info='Adds parameters to generated images allowing manual regeneration.') - metadata_scheme = gr.Radio(label='Metadata Scheme', choices=flags.metadata_scheme, value=modules.config.default_metadata_scheme, info='Image Prompt parameters are not included. Use a1111 for compatibility with Civitai.', visible=modules.config.default_save_metadata_to_images) - save_metadata_to_images.change(lambda x: gr.update(visible=x), inputs=[save_metadata_to_images], outputs=[metadata_scheme], queue=False, show_progress=False) + save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images, + info='Adds parameters to generated images allowing manual regeneration.') + metadata_scheme = gr.Radio(label='Metadata Scheme', choices=flags.metadata_scheme, value=modules.config.default_metadata_scheme, + info='Image Prompt parameters are not included. Use a1111 for compatibility with Civitai.', + visible=modules.config.default_save_metadata_to_images) + + save_metadata_to_images.change(lambda x: gr.update(visible=x), inputs=[save_metadata_to_images], outputs=[metadata_scheme], + queue=False, show_progress=False) + with gr.Tab(label='Control'): - debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False, info='See the results from preprocessors.') - skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False, info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)') - mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale', value=False) - mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint', value=False) - controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0, step=0.001, value=0.25, info='Similar to the Control Mode in A1111 (use 0.0 to disable). ') + debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False, + info='See the results from preprocessors.') + skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False, + info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)') + + mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale', + value=False) + mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint', + value=False) + + controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0, + step=0.001, value=0.25, + info='Similar to the Control Mode in A1111 (use 0.0 to disable). ') + with gr.Tab(label='Canny'): - canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255, step=1, value=64) - canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255, step=1, value=128) + canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255, + step=1, value=64) + canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255, + step=1, value=128) with gr.Tab(label='Inpaint'): debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False) inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False) - inpaint_engine = gr.Dropdown(label='Inpaint Engine', value=modules.config.default_inpaint_engine_version, choices=flags.inpaint_engine_versions, info='Version of Fooocus inpaint model') - inpaint_strength = gr.Slider(label='Inpaint Denoising Strength', minimum=0.0, maximum=1.0, step=0.001, value=1.0, info='Same as the denoising strength in A1111 inpaint. Only used in inpaint, not used in outpaint. (Outpaint always use 1.0)') - inpaint_respective_field = gr.Slider(label='Inpaint Respective Field', minimum=0.0, maximum=1.0, step=0.001, value=0.618, info='The area to inpaint. Value 0 is same as "Only Masked" in A1111. Value 1 is same as "Whole Image" in A1111. Only used in inpaint, not used in outpaint. (Outpaint always use 1.0)') - inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate', minimum=-64, maximum=64, step=1, value=0, info='Positive value will make white area in the mask larger, negative value will make white area smaller. (default is 0, always process before any mask invert)') + inpaint_engine = gr.Dropdown(label='Inpaint Engine', + value=modules.config.default_inpaint_engine_version, + choices=flags.inpaint_engine_versions, + info='Version of Fooocus inpaint model') + inpaint_strength = gr.Slider(label='Inpaint Denoising Strength', + minimum=0.0, maximum=1.0, step=0.001, value=1.0, + info='Same as the denoising strength in A1111 inpaint. ' + 'Only used in inpaint, not used in outpaint. ' + '(Outpaint always use 1.0)') + inpaint_respective_field = gr.Slider(label='Inpaint Respective Field', + minimum=0.0, maximum=1.0, step=0.001, value=0.618, + info='The area to inpaint. ' + 'Value 0 is same as "Only Masked" in A1111. ' + 'Value 1 is same as "Whole Image" in A1111. ' + 'Only used in inpaint, not used in outpaint. ' + '(Outpaint always use 1.0)') + inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate', + minimum=-64, maximum=64, step=1, value=0, + info='Positive value will make white area in the mask larger, ' + 'negative value will make white area smaller.' + '(default is 0, always process before any mask invert)') inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False) invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False) - inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate] - inpaint_mask_upload_checkbox.change(lambda x: [gr.update(visible=x)] * 2, inputs=inpaint_mask_upload_checkbox, outputs=[inpaint_mask_image, inpaint_mask_generation_col], queue=False, show_progress=False) + + inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, + inpaint_strength, inpaint_respective_field, + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate] + + inpaint_mask_upload_checkbox.change(lambda x: [gr.update(visible=x)] * 2, + inputs=inpaint_mask_upload_checkbox, + outputs=[inpaint_mask_image, inpaint_mask_generation_col], + queue=False, show_progress=False) with gr.Tab(label='FreeU'): freeu_enabled = gr.Checkbox(label='Enabled', value=False) @@ -405,13 +667,16 @@ def update_history_link(): def dev_mode_checked(r): return gr.update(visible=r) - dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools], queue=False, show_progress=False) + + dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools], + queue=False, show_progress=False) def model_refresh_clicked(): modules.config.update_all_model_names() modules.config.update_presets() results = [] - results += [gr.update(choices=modules.config.model_filenames), gr.update(choices=['None'] + modules.config.model_filenames)] + results += [gr.update(choices=modules.config.model_filenames), + gr.update(choices=['None'] + modules.config.model_filenames)] if not args_manager.args.disable_preset_selection: results += [gr.update(choices=modules.config.available_presets)] for i in range(flags.lora_count): @@ -421,29 +686,18 @@ def model_refresh_clicked(): model_refresh_output = [base_model, refiner_model] if not args_manager.args.disable_preset_selection: model_refresh_output += [preset_selection] - model_refresh.click(model_refresh_clicked, [], model_refresh_output + lora_ctrls, queue=False, show_progress=False) - - with gr.Tab(label='Audio'): - play_notification = gr.Checkbox(label='Play notification after rendering', value=False) - notification_file = 'notification.mp3' - if os.path.exists(notification_file): - notification = gr.State(value=notification_file) - notification_input = gr.Audio(label='Notification', interactive=True, elem_id='audio_notification', visible=False, show_edit_button=False) - - def play_notification_checked(r, notification): - return gr.update(visible=r, value=notification if r else None) - - def notification_input_changed(notification_input, notification): - if notification_input: - notification = notification_input - return notification - - play_notification.change(fn=play_notification_checked, inputs=[play_notification, notification], outputs=[notification_input], queue=False) - notification_input.change(fn=notification_input_changed, inputs=[notification_input, notification], outputs=[notification], queue=False) + model_refresh.click(model_refresh_clicked, [], model_refresh_output + lora_ctrls, + queue=False, show_progress=False) + state_is_generating = gr.State(False) - load_data_outputs = [advanced_checkbox, image_number, prompt, negative_prompt, style_selections, performance_selection, overwrite_step, overwrite_switch, aspect_ratios_selection, overwrite_width, overwrite_height, guidance_scale, sharpness, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, refiner_swap_method, adaptive_cfg, base_model, refiner_model, refiner_switch, sampler_name, scheduler_name, seed_random, image_seed, generate_button, load_parameter_button] + freeu_ctrls + lora_ctrls + load_data_outputs = [advanced_checkbox, image_number, prompt, negative_prompt, style_selections, + performance_selection, overwrite_step, overwrite_switch, aspect_ratios_selection, + overwrite_width, overwrite_height, guidance_scale, sharpness, adm_scaler_positive, + adm_scaler_negative, adm_scaler_end, refiner_swap_method, adaptive_cfg, base_model, + refiner_model, refiner_switch, sampler_name, scheduler_name, seed_random, image_seed, + generate_button, load_parameter_button] + freeu_ctrls + lora_ctrls if not args_manager.args.disable_preset_selection: def preset_selection_change(preset, is_generating): @@ -456,33 +710,74 @@ def preset_selection_change(preset, is_generating): embeddings_downloads = preset_prepared.get('embeddings_downloads', {}) lora_downloads = preset_prepared.get('lora_downloads', {}) - preset_prepared['base_model'], preset_prepared['lora_downloads'] = launch.download_models(default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads) + preset_prepared['base_model'], preset_prepared['lora_downloads'] = launch.download_models( + default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads) if 'prompt' in preset_prepared and preset_prepared.get('prompt') == '': del preset_prepared['prompt'] return modules.meta_parser.load_parameter_button_click(json.dumps(preset_prepared), is_generating) - preset_selection.change(preset_selection_change, inputs=[preset_selection, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True).then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False).then(lambda: None, _js='()=>{refresh_style_localization();}') + preset_selection.change(preset_selection_change, inputs=[preset_selection, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True) \ + .then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \ + .then(lambda: None, _js='()=>{refresh_style_localization();}') - performance_selection.change(lambda x: [gr.update(interactive=x != 'Extreme Speed')] * 11 + [gr.update(visible=x != 'Extreme Speed')] * 1 + [gr.update(interactive=x != 'Extreme Speed', value=x == 'Extreme Speed', )] * 1, inputs=performance_selection, outputs=[guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive, adm_scaler_negative, refiner_switch, refiner_model, sampler_name, scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt, disable_intermediate_results], queue=False, show_progress=False) + performance_selection.change(lambda x: [gr.update(interactive=x != 'Extreme Speed')] * 11 + + [gr.update(visible=x != 'Extreme Speed')] * 1 + + [gr.update(interactive=x != 'Extreme Speed', value=x == 'Extreme Speed', )] * 1, + inputs=performance_selection, + outputs=[ + guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive, + adm_scaler_negative, refiner_switch, refiner_model, sampler_name, + scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt, disable_intermediate_results + ], queue=False, show_progress=False) + output_format.input(lambda x: gr.update(output_format=x), inputs=output_format) - advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column, queue=False, show_progress=False).then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False) + advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column, + queue=False, show_progress=False) \ + .then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False) def inpaint_mode_change(mode): assert mode in modules.flags.inpaint_options + + # inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, + # inpaint_disable_initial_latent, inpaint_engine, + # inpaint_strength, inpaint_respective_field + if mode == modules.flags.inpaint_option_detail: - return [gr.update(visible=True), gr.update(visible=False, value=[]), gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts), False, 'None', 0.5, 0.0] - if mode == modules.flags.inpaint_option_modify: - return [gr.update(visible=True), gr.update(visible=False, value=[]), gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), True, modules.config.default_inpaint_engine_version, 1.0, 0.0] - return [gr.update(visible=False, value=''), gr.update(visible=True), gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), False, modules.config.default_inpaint_engine_version, 1.0, 0.618] + return [ + gr.update(visible=True), gr.update(visible=False, value=[]), + gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts), + False, 'None', 0.5, 0.0 + ] - inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field], show_progress=False, queue=False) + if mode == modules.flags.inpaint_option_modify: + return [ + gr.update(visible=True), gr.update(visible=False, value=[]), + gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), + True, modules.config.default_inpaint_engine_version, 1.0, 0.0 + ] + + return [ + gr.update(visible=False, value=''), gr.update(visible=True), + gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), + False, modules.config.default_inpaint_engine_version, 1.0, 0.618 + ] + + inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[ + inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, + inpaint_disable_initial_latent, inpaint_engine, + inpaint_strength, inpaint_respective_field + ], show_progress=False, queue=False) ctrls = [currentTask, generate_image_grid] - ctrls += [prompt, negative_prompt, translate_prompts, style_selections, performance_selection, aspect_ratios_selection, image_number, output_format, image_seed, sharpness, guidance_scale] + ctrls += [ + prompt, negative_prompt, translate_prompts, style_selections, + performance_selection, aspect_ratios_selection, image_number, output_format, image_seed, sharpness, guidance_scale + ] + ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] @@ -496,22 +791,27 @@ def inpaint_mode_change(mode): ctrls += [refiner_swap_method, controlnet_softness] ctrls += freeu_ctrls ctrls += inpaint_ctrls + if not args_manager.args.disable_metadata: ctrls += [save_metadata_to_images, metadata_scheme] + ctrls += ip_ctrls def parse_meta(raw_prompt_txt, is_generating): loaded_json = None if is_json(raw_prompt_txt): loaded_json = json.loads(raw_prompt_txt) + if loaded_json is None: if is_generating: return gr.update(), gr.update(), gr.update() else: return gr.update(), gr.update(visible=True), gr.update(visible=False) + return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=True) prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False) + load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=False) def trigger_metadata_import(filepath, state_is_generating): @@ -522,11 +822,21 @@ def trigger_metadata_import(filepath, state_is_generating): else: metadata_parser = modules.meta_parser.get_metadata_parser(metadata_scheme) parsed_parameters = metadata_parser.parse_json(parameters) + return modules.meta_parser.load_parameter_button_click(parsed_parameters, state_is_generating) - metadata_import_button.click(trigger_metadata_import, inputs=[metadata_input_image, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True).then(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) + metadata_import_button.click(trigger_metadata_import, inputs=[metadata_input_image, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True) \ + .then(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) - generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True), outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]).then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed).then(fn=get_task, inputs=ctrls, outputs=currentTask).then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]).then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False), outputs=[generate_button, stop_button, skip_button, state_is_generating]).then(fn=update_history_link, outputs=history_link).then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') + generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True), + outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \ + .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ + .then(fn=get_task, inputs=ctrls, outputs=currentTask) \ + .then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ + .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False), + outputs=[generate_button, stop_button, skip_button, state_is_generating]) \ + .then(fn=update_history_link, outputs=history_link) \ + .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') def trigger_describe(mode, img): if mode == flags.desc_type_photo: @@ -537,17 +847,31 @@ def trigger_describe(mode, img): return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"] return mode, ["Fooocus V2"] - desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image], outputs=[prompt, style_selections], show_progress=True, queue=True) + desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image], + outputs=[prompt, style_selections], show_progress=True, queue=True) def trigger_uov_describe(mode, img, prompt): + # keep prompt if not empty if prompt == '': return trigger_describe(mode, img) return gr.update(), gr.update() - uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], outputs=[prompt, style_selections], show_progress=True, queue=True) + uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], + outputs=[prompt, style_selections], show_progress=True, queue=True) def dump_default_english_config(): from modules.localization import dump_english_config dump_english_config(grh.all_components) -shared.gradio_root.launch(inbrowser=args_manager.args.in_browser, server_name=args_manager.args.listen, server_port=args_manager.args.port, share=args_manager.args.share, favicon_path="assets/favicon.png", auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None, blocked_paths=[constants.AUTH_FILENAME]) + +# dump_default_english_config() + +shared.gradio_root.launch( + inbrowser=args_manager.args.in_browser, + server_name=args_manager.args.listen, + server_port=args_manager.args.port, + share=args_manager.args.share, + favicon_path="assets/favicon.png", + auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None, + blocked_paths=[constants.AUTH_FILENAME] +) \ No newline at end of file From a12e8a1a4381e1e21e90b378d39fe1cbeec2349b Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 07:20:30 +0500 Subject: [PATCH 18/32] Yar lets ttry again 2 --- webui.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/webui.py b/webui.py index f181366f6..d68bbfdfd 100644 --- a/webui.py +++ b/webui.py @@ -190,18 +190,12 @@ def skip_clicked(currentTask): stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever') skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False) with gr.Row(elem_classes='advanced_check_row'): - input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check') - advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check') + input_image_checkbox = gr.Checkbox(label='Input Image', value=True, visible=False, container=False, elem_classes='min_check') + advanced_checkbox = gr.Checkbox(label='Advanced', value=True, visible=False, container=False, elem_classes='min_check') + with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): - with gr.TabItem(label='Upscale or Variation') as uov_tab: - with gr.Row(): - with gr.Column(): - uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') - with gr.Column(): - uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) - gr.HTML('\U0001F4D4 Document') with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -217,13 +211,11 @@ def skip_clicked(currentTask): ip_ctrls.append(ip_image) with gr.Column(visible=False) as ad_col: with gr.Row(): - default_end, default_weight = flags.default_parameters[flags.default_ip] - - ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end) + ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=0.85, visible=False) ip_stops.append(ip_stop) ip_ctrls.append(ip_stop) - ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight) + ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=0.97, visible=False) ip_weights.append(ip_weight) ip_ctrls.append(ip_weight) @@ -239,12 +231,12 @@ def skip_clicked(currentTask): def ip_advance_checked(x): return [gr.update(visible=x)] * len(ip_ad_cols) + \ [flags.default_ip] * len(ip_types) + \ - [flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \ - [flags.default_parameters[flags.default_ip][1]] * len(ip_weights) + [0.85] * len(ip_stops) + \ + [0.97] * len(ip_weights) ip_advanced.change(ip_advance_checked, inputs=ip_advanced, - outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, - queue=False, show_progress=False) + outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, + queue=False, show_progress=False) with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab: with gr.Row(): @@ -350,7 +342,7 @@ def trigger_metadata_preview(filepath): ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) current_tab = gr.Textbox(value='uov', visible=False) - uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) + #uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False) From 050bcb784e44dfdc49f612b0cbfb17deaf181163 Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 08:56:59 +0500 Subject: [PATCH 19/32] Yar lets ttry again 3 --- webui.py | 122 ++++++++++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 74 deletions(-) diff --git a/webui.py b/webui.py index d68bbfdfd..4d8e8d45b 100644 --- a/webui.py +++ b/webui.py @@ -14,7 +14,6 @@ import modules.style_sorter as style_sorter import modules.meta_parser from modules.rembg import rembg_run -from modules.load_online import load_demos_names, load_tools_names, load_demos_url, load_tools_url import args_manager import copy import launch @@ -125,9 +124,7 @@ def generate_clicked(task): elem_id='progress-bar', elem_classes='progress-bar') gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768, elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'], - elem_id='final_gallery', - value=["assets/favicon.png"], - preview=True) + elem_id='final_gallery') with gr.Tab("Photopea"): with gr.Row(): photopea = gr.HTML( @@ -138,26 +135,14 @@ def generate_clicked(task): onload = "{PHOTOPEA_IFRAME_LOADED_EVENT}(this)">""" ) gr.Markdown("Powered by [🦜 Photopea API](https://www.photopea.com/api)") - with gr.Tab("rembg"): + with gr.Tab("rembg", visible=False): with gr.Column(scale=1): rembg_input = grh.Image(label='Drag above image to here', source='upload', type='filepath', scale=20) rembg_button = gr.Button(value="Remove Background", interactive=True, scale=1) with gr.Column(scale=3): rembg_output = grh.Image(label='rembg Output', interactive=False, height=380) gr.Markdown("Powered by [🪄 rembg 2.0.53](https://github.com/danielgatis/rembg/releases/tag/v2.0.53)") - rembg_button.click(rembg_run, inputs=rembg_input, outputs=rembg_output, show_progress="full") - with gr.Tab("Online"): - with gr.Tab("Demos"): - for name in load_demos_names(): - url = load_demos_url(name) - with gr.Tab(name): - gr.HTML(f"") - with gr.Tab("Tools"): - for name in load_tools_names(): - url = load_tools_url(name) - with gr.Tab(name): - gr.HTML(f"") - + rembg_button.click(rembg_run, inputs=rembg_input, outputs=rembg_output, show_progress="full") with gr.Row(elem_classes='type_row'): with gr.Column(scale=17): prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt', @@ -196,6 +181,13 @@ def skip_clicked(currentTask): with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): + # with gr.TabItem(label='Upscale or Variation') as uov_tab: + # with gr.Row(): + # with gr.Column(): + # uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') + # with gr.Column(): + # uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) + # gr.HTML('\U0001F4D4 Document') with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -211,11 +203,13 @@ def skip_clicked(currentTask): ip_ctrls.append(ip_image) with gr.Column(visible=False) as ad_col: with gr.Row(): - ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=0.85, visible=False) + # default_end, default_weight = flags.default_parameters[flags.default_ip] + + ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end) ip_stops.append(ip_stop) ip_ctrls.append(ip_stop) - ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=0.97, visible=False) + ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight) ip_weights.append(ip_weight) ip_ctrls.append(ip_weight) @@ -235,8 +229,8 @@ def ip_advance_checked(x): [0.97] * len(ip_weights) ip_advanced.change(ip_advance_checked, inputs=ip_advanced, - outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, - queue=False, show_progress=False) + outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, + queue=False, show_progress=False) with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab: with gr.Row(): @@ -342,44 +336,26 @@ def trigger_metadata_preview(filepath): ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) current_tab = gr.Textbox(value='uov', visible=False) - #uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) + # uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False) with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column: with gr.Tab(label='Settings'): - with gr.Row(): - performance_selection = gr.Radio(label='Performance', - choices=modules.flags.performance_selections, - value=modules.config.default_performance, - elem_classes='performance_selections') - if not args_manager.args.disable_preset_selection: - preset_selection = gr.Dropdown(label='Preset', - choices=modules.config.available_presets, - value=args_manager.args.preset if args_manager.args.preset else "initial", - interactive=True) - + performance_selection = gr.Radio(label='Performance', + choices=modules.flags.performance_selections, + value=modules.config.default_performance, + elem_classes='performance_selections') + if not args_manager.args.disable_preset_selection: + preset_selection = gr.Radio(label='Preset', + choices=modules.config.available_presets, + value=args_manager.args.preset if args_manager.args.preset else "initial", + interactive=True) + aspect_ratios_selection = gr.Radio(label='Aspect Ratios', choices=modules.config.available_aspect_ratios, value=modules.config.default_aspect_ratio, info='width × height', elem_classes='aspect_ratios') - - with gr.Column(): - sampling_apply = gr.Checkbox(label="Sampling", value=False) - with gr.Row(visible=False) as sampling: - sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, - value=modules.config.default_sampler) - scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, - value=modules.config.default_scheduler) - sampling_apply.change( - fn=lambda x: gr.update(visible=x), - inputs=sampling_apply, - outputs=sampling, - queue=False, - api_name=False, - ) - - image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number) @@ -495,27 +471,9 @@ def update_history_link(): choices=modules.flags.output_formats, value=modules.config.default_output_format) - play_notification = gr.Checkbox(label='Play notification after rendering', value=False) - notification_file = 'notification.mp3' - if os.path.exists(notification_file): - notification = gr.State(value=notification_file) - notification_input = gr.Audio(label='Notification', interactive=True, elem_id='audio_notification', visible=False, show_edit_button=False) - - def play_notification_checked(r, notification): - return gr.update(visible=r, value=notification if r else None) - - def notification_input_changed(notification_input, notification): - if notification_input: - notification = notification_input - return notification - - play_notification.change(fn=play_notification_checked, inputs=[play_notification, notification], outputs=[notification_input], queue=False) - notification_input.change(fn=notification_input_changed, inputs=[notification_input, notification], outputs=[notification], queue=False) - - - dev_mode = gr.Checkbox(label='Advanced mode', value=True, container=False) + dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False) - with gr.Column(visible=True) as dev_tools: + with gr.Column(visible=False) as dev_tools: with gr.Tab(label='Debug Tools'): adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0, step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ') @@ -532,12 +490,11 @@ def notification_input_changed(notification_input, notification): value=modules.config.default_cfg_tsnr, info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR ' '(effective when real CFG > mimicked CFG).') - ''' sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, value=modules.config.default_sampler) scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, value=modules.config.default_scheduler) - ''' + generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch', info='(Experimental) This may cause performance problems on some computers and certain internet conditions.', value=False) @@ -681,7 +638,24 @@ def model_refresh_clicked(): model_refresh.click(model_refresh_clicked, [], model_refresh_output + lora_ctrls, queue=False, show_progress=False) - + with gr.Tab(label='Audio'): + play_notification = gr.Checkbox(label='Play notification after rendering', value=False) + notification_file = 'notification.mp3' + if os.path.exists(notification_file): + notification = gr.State(value=notification_file) + notification_input = gr.Audio(label='Notification', interactive=True, elem_id='audio_notification', visible=False, show_edit_button=False) + + def play_notification_checked(r, notification): + return gr.update(visible=r, value=notification if r else None) + + def notification_input_changed(notification_input, notification): + if notification_input: + notification = notification_input + return notification + + play_notification.change(fn=play_notification_checked, inputs=[play_notification, notification], outputs=[notification_input], queue=False) + notification_input.change(fn=notification_input_changed, inputs=[notification_input, notification], outputs=[notification], queue=False) + state_is_generating = gr.State(False) load_data_outputs = [advanced_checkbox, image_number, prompt, negative_prompt, style_selections, From a11fcb9a08535605bdfb39ec875e0e39a515c0ac Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 09:07:55 +0500 Subject: [PATCH 20/32] Yar lets ttry again 4 --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 4d8e8d45b..a528c78d5 100644 --- a/webui.py +++ b/webui.py @@ -205,11 +205,11 @@ def skip_clicked(currentTask): with gr.Row(): # default_end, default_weight = flags.default_parameters[flags.default_ip] - ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end) + ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=0.85, visible=False) ip_stops.append(ip_stop) ip_ctrls.append(ip_stop) - ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight) + ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=0.97, visible=False) ip_weights.append(ip_weight) ip_ctrls.append(ip_weight) From 1fe0bd932d4f1a4bd3591a3c06603e41485e832a Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 09:18:09 +0500 Subject: [PATCH 21/32] Yar lets ttry again 5 --- webui.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/webui.py b/webui.py index a528c78d5..21ea17924 100644 --- a/webui.py +++ b/webui.py @@ -181,13 +181,7 @@ def skip_clicked(currentTask): with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): - # with gr.TabItem(label='Upscale or Variation') as uov_tab: - # with gr.Row(): - # with gr.Column(): - # uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') - # with gr.Column(): - # uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) - # gr.HTML('\U0001F4D4 Document') + with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -335,8 +329,7 @@ def trigger_metadata_preview(filepath): outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js) ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) - current_tab = gr.Textbox(value='uov', visible=False) - # uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) + inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False) @@ -746,7 +739,6 @@ def inpaint_mode_change(mode): ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls ctrls += [input_image_checkbox, current_tab] - ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] ctrls += [disable_preview, disable_intermediate_results, black_out_nsfw] ctrls += [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] @@ -816,14 +808,6 @@ def trigger_describe(mode, img): desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image], outputs=[prompt, style_selections], show_progress=True, queue=True) - def trigger_uov_describe(mode, img, prompt): - # keep prompt if not empty - if prompt == '': - return trigger_describe(mode, img) - return gr.update(), gr.update() - - uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], - outputs=[prompt, style_selections], show_progress=True, queue=True) def dump_default_english_config(): from modules.localization import dump_english_config From 11265e7c9fe7f3430a950cae2e47f1e9d661f95c Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 09:39:54 +0500 Subject: [PATCH 22/32] Yar lets ttry again 6 --- webui.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 21ea17924..24fca4b41 100644 --- a/webui.py +++ b/webui.py @@ -181,7 +181,13 @@ def skip_clicked(currentTask): with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): - + with gr.TabItem(label='Upscale or Variation', visible=False) as uov_tab: + with gr.Row(): + with gr.Column(): + uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') + with gr.Column(): + uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) + gr.HTML('\U0001F4D4 Document') with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -329,7 +335,8 @@ def trigger_metadata_preview(filepath): outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js) ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) - + current_tab = gr.Textbox(value='uov', visible=False) + uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False) @@ -739,6 +746,7 @@ def inpaint_mode_change(mode): ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls ctrls += [input_image_checkbox, current_tab] + ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] ctrls += [disable_preview, disable_intermediate_results, black_out_nsfw] ctrls += [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] @@ -808,6 +816,14 @@ def trigger_describe(mode, img): desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image], outputs=[prompt, style_selections], show_progress=True, queue=True) + def trigger_uov_describe(mode, img, prompt): + # keep prompt if not empty + if prompt == '': + return trigger_describe(mode, img) + return gr.update(), gr.update() + + uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], + outputs=[prompt, style_selections], show_progress=True, queue=True) def dump_default_english_config(): from modules.localization import dump_english_config From d3cb26f2bc1b7d19dac54078587c773d309d32dc Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 09:47:35 +0500 Subject: [PATCH 23/32] Yar lets ttry again 7 --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 24fca4b41..98d9eacbd 100644 --- a/webui.py +++ b/webui.py @@ -181,7 +181,7 @@ def skip_clicked(currentTask): with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): - with gr.TabItem(label='Upscale or Variation', visible=False) as uov_tab: + with gr.TabItem(label='Upscale or Variation') as uov_tab: with gr.Row(): with gr.Column(): uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') From e713992ba692645b957c2e513e5625258b80b742 Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 09:58:21 +0500 Subject: [PATCH 24/32] Yar lets ttry again 8 --- modules/config.py | 2 +- webui.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/config.py b/modules/config.py index 4e83568cd..97b2ff183 100644 --- a/modules/config.py +++ b/modules/config.py @@ -326,7 +326,7 @@ def get_config_item_or_set_default(key, default_value, validator, disable_empty_ ) default_advanced_checkbox = get_config_item_or_set_default( key='default_advanced_checkbox', - default_value=False, + default_value=True, validator=lambda x: isinstance(x, bool) ) default_max_image_number = get_config_item_or_set_default( diff --git a/webui.py b/webui.py index 98d9eacbd..f78f78e42 100644 --- a/webui.py +++ b/webui.py @@ -175,9 +175,8 @@ def skip_clicked(currentTask): stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever') skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False) with gr.Row(elem_classes='advanced_check_row'): - input_image_checkbox = gr.Checkbox(label='Input Image', value=True, visible=False, container=False, elem_classes='min_check') - advanced_checkbox = gr.Checkbox(label='Advanced', value=True, visible=False, container=False, elem_classes='min_check') - + input_image_checkbox = gr.Checkbox(label='Input Image', value=True, container=False, elem_classes='min_check') + advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check') with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): @@ -203,13 +202,13 @@ def skip_clicked(currentTask): ip_ctrls.append(ip_image) with gr.Column(visible=False) as ad_col: with gr.Row(): - # default_end, default_weight = flags.default_parameters[flags.default_ip] + default_end, default_weight = flags.default_parameters[flags.default_ip] - ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=0.85, visible=False) + ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end) ip_stops.append(ip_stop) ip_ctrls.append(ip_stop) - ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=0.97, visible=False) + ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight) ip_weights.append(ip_weight) ip_ctrls.append(ip_weight) @@ -225,8 +224,8 @@ def skip_clicked(currentTask): def ip_advance_checked(x): return [gr.update(visible=x)] * len(ip_ad_cols) + \ [flags.default_ip] * len(ip_types) + \ - [0.85] * len(ip_stops) + \ - [0.97] * len(ip_weights) + [flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \ + [flags.default_parameters[flags.default_ip][1]] * len(ip_weights) ip_advanced.change(ip_advance_checked, inputs=ip_advanced, outputs=ip_ad_cols + ip_types + ip_stops + ip_weights, From a789761ffac4c044c44292878cceb55f4f738d48 Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 10:03:02 +0500 Subject: [PATCH 25/32] Yar lets ttry again 9 --- webui.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/webui.py b/webui.py index f78f78e42..c24fc3557 100644 --- a/webui.py +++ b/webui.py @@ -180,13 +180,13 @@ def skip_clicked(currentTask): with gr.Row(visible=False) as image_input_panel: with gr.Tabs(): - with gr.TabItem(label='Upscale or Variation') as uov_tab: - with gr.Row(): - with gr.Column(): - uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') - with gr.Column(): - uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) - gr.HTML('\U0001F4D4 Document') + # with gr.TabItem(label='Upscale or Variation') as uov_tab: + # with gr.Row(): + # with gr.Column(): + # uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy') + # with gr.Column(): + # uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled) + # gr.HTML('\U0001F4D4 Document') with gr.TabItem(label='Image Prompt') as ip_tab: with gr.Row(): ip_images = [] @@ -335,7 +335,7 @@ def trigger_metadata_preview(filepath): ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js) current_tab = gr.Textbox(value='uov', visible=False) - uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) + # uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False) From 86038dc5a92efb04c647bb201b069989f234aeca Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 10:13:24 +0500 Subject: [PATCH 26/32] Yar lets ttry again 0 --- modules/async_worker.py | 6 +++--- webui.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 50263cec8..c25bbb1dc 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -156,8 +156,8 @@ def handler(async_task): loras = [[str(args.pop()), float(args.pop())] for _ in range(lora_count)] input_image_checkbox = args.pop() current_tab = args.pop() - uov_method = args.pop() - uov_input_image = args.pop() + # uov_method = args.pop() + # uov_input_image = args.pop() outpaint_selections = args.pop() inpaint_input_image = args.pop() inpaint_additional_prompt = args.pop() @@ -215,7 +215,7 @@ def handler(async_task): outpaint_selections = [o.lower() for o in outpaint_selections] base_model_additional_loras = [] raw_style_selections = copy.deepcopy(style_selections) - uov_method = uov_method.lower() + # uov_method = uov_method.lower() if fooocus_expansion in style_selections: use_expansion = True diff --git a/webui.py b/webui.py index c24fc3557..7e31f394d 100644 --- a/webui.py +++ b/webui.py @@ -745,7 +745,7 @@ def inpaint_mode_change(mode): ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls ctrls += [input_image_checkbox, current_tab] - ctrls += [uov_method, uov_input_image] + # ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] ctrls += [disable_preview, disable_intermediate_results, black_out_nsfw] ctrls += [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] @@ -821,8 +821,8 @@ def trigger_uov_describe(mode, img, prompt): return trigger_describe(mode, img) return gr.update(), gr.update() - uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], - outputs=[prompt, style_selections], show_progress=True, queue=True) + # uov_input_image.upload(trigger_uov_describe, inputs=[desc_method, uov_input_image, prompt], + # outputs=[prompt, style_selections], show_progress=True, queue=True) def dump_default_english_config(): from modules.localization import dump_english_config From be95870cb257d50945530fca4da79019de45af72 Mon Sep 17 00:00:00 2001 From: ateeb Date: Tue, 18 Jun 2024 10:25:05 +0500 Subject: [PATCH 27/32] Yar lets ttry again 11 --- webui.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/webui.py b/webui.py index 7e31f394d..ff4c3c235 100644 --- a/webui.py +++ b/webui.py @@ -13,7 +13,7 @@ import modules.gradio_hijack as grh import modules.style_sorter as style_sorter import modules.meta_parser -from modules.rembg import rembg_run +# from modules.rembg import rembg_run import args_manager import copy import launch @@ -24,15 +24,15 @@ from modules.auth import auth_enabled, check_auth from modules.util import is_json -PHOTOPEA_MAIN_URL = "https://www.photopea.com/" -PHOTOPEA_IFRAME_ID = "webui-photopea-iframe" -PHOTOPEA_IFRAME_HEIGHT = 684 -PHOTOPEA_IFRAME_WIDTH = "100%" -PHOTOPEA_IFRAME_LOADED_EVENT = "onPhotopeaLoaded" +# PHOTOPEA_MAIN_URL = "https://www.photopea.com/" +# PHOTOPEA_IFRAME_ID = "webui-photopea-iframe" +# PHOTOPEA_IFRAME_HEIGHT = 684 +# PHOTOPEA_IFRAME_WIDTH = "100%" +# PHOTOPEA_IFRAME_LOADED_EVENT = "onPhotopeaLoaded" -def get_photopea_url_params(): - return "#%7B%22resources%22:%5B%22data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAQMAAADOtka5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRF////p8QbyAAAADZJREFUeJztwQEBAAAAgiD/r25IQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfBuCAAAB0niJ8AAAAABJRU5ErkJggg==%22%5D%7D" +# def get_photopea_url_params(): +# return "#%7B%22resources%22:%5B%22data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAQMAAADOtka5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRF////p8QbyAAAADZJREFUeJztwQEBAAAAgiD/r25IQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfBuCAAAB0niJ8AAAAABJRU5ErkJggg==%22%5D%7D" def get_task(*args): @@ -125,24 +125,24 @@ def generate_clicked(task): gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768, elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'], elem_id='final_gallery') - with gr.Tab("Photopea"): - with gr.Row(): - photopea = gr.HTML( - f"""