Download ui/events/main.py from Gramlin/ImageGen: direct link, hf CLI and curl.
- Browser
- Download file 25.3 kB
-
https://huggingface.co/spaces/Gramlin/ImageGen/resolve/main/ui/events/main.py
- Command line
-
hf download hf://spaces/Gramlin/ImageGen/ui/events/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Gramlin/ImageGen/resolve/main/ui/events/main.py
25.3 kB
| import gradio as gr | |
| from .chain_handlers import ( | |
| create_lora_event_handlers, | |
| create_controlnet_event_handlers, | |
| create_ipadapter_event_handlers, | |
| create_embedding_event_handlers, | |
| create_conditioning_event_handlers, | |
| create_flux1_ipadapter_event_handlers, | |
| create_sd3_ipadapter_event_handlers, | |
| create_style_event_handlers, | |
| create_reference_latent_event_handlers, | |
| create_hidream_o1_reference_event_handlers, | |
| create_sensenova_reference_event_handlers, | |
| create_joyai_reference_event_handlers, | |
| create_krea2_identity_edit_event_handlers, | |
| create_krea2_reference_edit_event_handlers, | |
| create_qwen_image_edit_event_handlers, | |
| create_reference_image_event_handlers | |
| ) | |
| from .change_handlers import ( | |
| make_update_fn, | |
| make_model_change_fn, | |
| run_on_load, | |
| on_aspect_ratio_change | |
| ) | |
| from .run_handlers import create_run_event | |
| def attach_event_handlers(ui_components, demo): | |
| prefixes = ["imagegen", "txt2img", "img2img", "inpaint", "outpaint", "hires_fix"] | |
| active_prefixes = [p for p in prefixes if f'base_model_{p}' in ui_components] | |
| for prefix in active_prefixes: | |
| task_type = prefix if prefix != "imagegen" else None | |
| type_comp = ui_components.get(f'type_{prefix}') # for unified imagegen UI | |
| arch_comp = ui_components.get(f'model_arch_{prefix}') | |
| cat_comp = ui_components.get(f'model_cat_{prefix}') | |
| model_comp = ui_components.get(f'base_model_{prefix}') | |
| aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown') | |
| width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width') | |
| height_comp = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height') | |
| cn_types_list = ui_components.get(f'controlnet_types_{prefix}', []) | |
| cn_series_list = ui_components.get(f'controlnet_series_{prefix}', []) | |
| cn_filepaths_list = ui_components.get(f'controlnet_filepaths_{prefix}', []) | |
| lora_accordion = ui_components.get(f'lora_accordion_{prefix}') | |
| cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}') | |
| ipa_accordion = ui_components.get(f'ipadapter_accordion_{prefix}') | |
| sd3_ipa_accordion = ui_components.get(f'sd3_ipadapter_accordion_{prefix}') | |
| flux1_ipa_accordion = ui_components.get(f'flux1_ipadapter_accordion_{prefix}') | |
| style_accordion = ui_components.get(f'style_accordion_{prefix}') | |
| embedding_accordion = ui_components.get(f'embedding_accordion_{prefix}') | |
| conditioning_accordion = ui_components.get(f'conditioning_accordion_{prefix}') | |
| ref_latent_accordion = ui_components.get(f'reference_latent_accordion_{prefix}') | |
| hidream_o1_ref_accordion = ui_components.get(f'hidream_o1_reference_accordion_{prefix}') | |
| sensenova_ref_accordion = ui_components.get(f'sensenova_reference_accordion_{prefix}') | |
| joyai_ref_accordion = ui_components.get(f'joyai_reference_accordion_{prefix}') | |
| krea2_identity_edit_accordion = ui_components.get(f'krea2_identity_edit_accordion_{prefix}') | |
| krea2_reference_edit_accordion = ui_components.get(f'krea2_reference_edit_accordion_{prefix}') | |
| qwen_image_edit_accordion = ui_components.get(f'qwen_image_edit_accordion_{prefix}') | |
| ref_img_accordion = ui_components.get(f'reference_image_accordion_{prefix}') | |
| pid_accordion = ui_components.get(f'pid_accordion_{prefix}') | |
| vae_accordion = ui_components.get(f'vae_accordion_{prefix}') | |
| qwen_pe_accordion = ui_components.get(f'qwen_image_2_1_prompt_enhancer_accordion_{prefix}') | |
| ming_pe_accordion = ui_components.get(f'ming_image_prompt_enhancer_accordion_{prefix}') | |
| ipa_preset_list = ui_components.get(f'ipadapter_final_preset_{prefix}') | |
| prompt_comp = ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt') | |
| neg_prompt_comp = ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt') | |
| steps_comp = ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps') | |
| cfg_comp = ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg') | |
| sampler_comp = ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name') | |
| scheduler_comp = ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler') | |
| extra_comps = [prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, width_comp, height_comp] | |
| valid_extra_comps = [c for c in extra_comps if c is not None] | |
| if arch_comp and cat_comp and model_comp: | |
| outputs = [model_comp, cat_comp] | |
| if aspect_ratio_comp: outputs.append(aspect_ratio_comp) | |
| outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list) | |
| if lora_accordion: outputs.append(lora_accordion) | |
| if cn_accordion: outputs.append(cn_accordion) | |
| if ipa_accordion: outputs.append(ipa_accordion) | |
| if sd3_ipa_accordion: outputs.append(sd3_ipa_accordion) | |
| if flux1_ipa_accordion: outputs.append(flux1_ipa_accordion) | |
| if style_accordion: outputs.append(style_accordion) | |
| if embedding_accordion: outputs.append(embedding_accordion) | |
| if conditioning_accordion: outputs.append(conditioning_accordion) | |
| if ref_latent_accordion: outputs.append(ref_latent_accordion) | |
| if hidream_o1_ref_accordion: outputs.append(hidream_o1_ref_accordion) | |
| if sensenova_ref_accordion: outputs.append(sensenova_ref_accordion) | |
| if joyai_ref_accordion: outputs.append(joyai_ref_accordion) | |
| if krea2_identity_edit_accordion: outputs.append(krea2_identity_edit_accordion) | |
| if krea2_reference_edit_accordion: outputs.append(krea2_reference_edit_accordion) | |
| if qwen_image_edit_accordion: outputs.append(qwen_image_edit_accordion) | |
| if ref_img_accordion: outputs.append(ref_img_accordion) | |
| if pid_accordion: outputs.append(pid_accordion) | |
| if vae_accordion: outputs.append(vae_accordion) | |
| if qwen_pe_accordion: outputs.append(qwen_pe_accordion) | |
| if ming_pe_accordion: outputs.append(ming_pe_accordion) | |
| if ipa_preset_list: outputs.append(ipa_preset_list) | |
| outputs.extend(valid_extra_comps) | |
| update_fn = make_update_fn( | |
| model_comp, cat_comp, aspect_ratio_comp, width_comp, height_comp, | |
| cn_types_list, cn_series_list, cn_filepaths_list, | |
| ipa_preset_list, lora_accordion, cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, | |
| ref_latent_accordion, hidream_o1_ref_accordion, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, | |
| pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, krea2_reference_edit_acc=krea2_reference_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion, sensenova_ref_acc=sensenova_ref_accordion, | |
| task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion, ming_pe_acc=ming_pe_accordion | |
| ) | |
| inputs = [arch_comp, cat_comp] | |
| if aspect_ratio_comp: | |
| inputs.append(aspect_ratio_comp) | |
| if type_comp: | |
| inputs.append(type_comp) | |
| arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs) | |
| cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs) | |
| if model_comp: | |
| outputs2 = [] | |
| if arch_comp: outputs2.append(arch_comp) | |
| if cat_comp: outputs2.append(cat_comp) | |
| if aspect_ratio_comp: outputs2.append(aspect_ratio_comp) | |
| outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list) | |
| if lora_accordion: outputs2.append(lora_accordion) | |
| if cn_accordion: outputs2.append(cn_accordion) | |
| if ipa_accordion: outputs2.append(ipa_accordion) | |
| if sd3_ipa_accordion: outputs2.append(sd3_ipa_accordion) | |
| if flux1_ipa_accordion: outputs2.append(flux1_ipa_accordion) | |
| if style_accordion: outputs2.append(style_accordion) | |
| if embedding_accordion: outputs2.append(embedding_accordion) | |
| if conditioning_accordion: outputs2.append(conditioning_accordion) | |
| if ref_latent_accordion: outputs2.append(ref_latent_accordion) | |
| if hidream_o1_ref_accordion: outputs2.append(hidream_o1_ref_accordion) | |
| if sensenova_ref_accordion: outputs2.append(sensenova_ref_accordion) | |
| if joyai_ref_accordion: outputs2.append(joyai_ref_accordion) | |
| if krea2_identity_edit_accordion: outputs2.append(krea2_identity_edit_accordion) | |
| if krea2_reference_edit_accordion: outputs2.append(krea2_reference_edit_accordion) | |
| if qwen_image_edit_accordion: outputs2.append(qwen_image_edit_accordion) | |
| if ref_img_accordion: outputs2.append(ref_img_accordion) | |
| if pid_accordion: outputs2.append(pid_accordion) | |
| if vae_accordion: outputs2.append(vae_accordion) | |
| if qwen_pe_accordion: outputs2.append(qwen_pe_accordion) | |
| if ming_pe_accordion: outputs2.append(ming_pe_accordion) | |
| if ipa_preset_list: outputs2.append(ipa_preset_list) | |
| outputs2.extend(valid_extra_comps) | |
| if outputs2: | |
| inputs2 = [model_comp] | |
| if arch_comp: inputs2.append(arch_comp) | |
| if cat_comp: inputs2.append(cat_comp) | |
| if aspect_ratio_comp: inputs2.append(aspect_ratio_comp) | |
| change_fn = make_model_change_fn( | |
| cat_comp, aspect_ratio_comp, width_comp, height_comp, | |
| cn_types_list, cn_series_list, cn_filepaths_list, | |
| arch_comp, ipa_preset_list, lora_accordion, cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, | |
| ref_latent_accordion, hidream_o1_ref_accordion, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, | |
| pid_acc=pid_accordion, vae_acc=vae_accordion, joyai_ref_acc=joyai_ref_accordion, krea2_identity_edit_acc=krea2_identity_edit_accordion, krea2_reference_edit_acc=krea2_reference_edit_accordion, qwen_image_edit_acc=qwen_image_edit_accordion, ref_img_acc=ref_img_accordion, sensenova_ref_acc=sensenova_ref_accordion, | |
| task_type=task_type, type_comp=type_comp, qwen_pe_acc=qwen_pe_accordion, ming_pe_acc=ming_pe_accordion | |
| ) | |
| if type_comp: | |
| inputs2.append(type_comp) | |
| model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2) | |
| create_lora_event_handlers(prefix, ui_components) | |
| create_controlnet_event_handlers(prefix, ui_components) | |
| create_ipadapter_event_handlers(prefix, ui_components) | |
| create_embedding_event_handlers(prefix, ui_components) | |
| create_conditioning_event_handlers(prefix, ui_components) | |
| create_flux1_ipadapter_event_handlers(prefix, ui_components) | |
| create_sd3_ipadapter_event_handlers(prefix, ui_components) | |
| create_style_event_handlers(prefix, ui_components) | |
| create_reference_latent_event_handlers(prefix, ui_components) | |
| create_hidream_o1_reference_event_handlers(prefix, ui_components) | |
| create_sensenova_reference_event_handlers(prefix, ui_components) | |
| create_joyai_reference_event_handlers(prefix, ui_components) | |
| create_krea2_identity_edit_event_handlers(prefix, ui_components) | |
| create_krea2_reference_edit_event_handlers(prefix, ui_components) | |
| create_qwen_image_edit_event_handlers(prefix, ui_components) | |
| create_reference_image_event_handlers(prefix, ui_components) | |
| create_run_event(prefix, task_type, ui_components) | |
| # Dynamic Type toggle event for unified imagegen UI | |
| if 'type_imagegen' in ui_components: | |
| def on_type_change(type_val, model_name): | |
| from core.settings import MODEL_TYPE_MAP, FEATURES_CONFIG, TASK_FEATURES_CONFIG, ARCHITECTURES_CONFIG | |
| is_txt2img = (type_val == "Txt2Img") | |
| is_img2img = (type_val == "Img2Img") | |
| is_inpaint = (type_val == "Inpaint") | |
| is_outpaint = (type_val == "Outpaint") | |
| is_hires_fix = (type_val == "Hires. Fix") | |
| denoise_val = 0.7 if is_img2img else (1.0 if is_inpaint else (0.55 if is_hires_fix else 0.7)) | |
| run_text = "Run Inpaint" if is_inpaint else ("Run Outpaint" if is_outpaint else ("Run Hires. Fix" if is_hires_fix else "Run")) | |
| prompt_lines = 6 if is_inpaint else 3 | |
| gallery_cols = 2 if is_txt2img else 1 | |
| gallery_height = 627 if is_txt2img else (505 if is_img2img else (510 if is_inpaint else (685 if is_outpaint else 610))) | |
| updates = { | |
| ui_components['image_input_col_imagegen']: gr.update(visible=not is_txt2img), | |
| ui_components['input_image_imagegen']: gr.update(visible=(is_img2img or is_outpaint or is_hires_fix)), | |
| ui_components['inpaint_box_imagegen']: gr.update(visible=is_inpaint), | |
| ui_components['prompt_imagegen']: gr.update(lines=prompt_lines), | |
| ui_components['neg_prompt_imagegen']: gr.update(lines=prompt_lines), | |
| ui_components['aspect_ratio_row_imagegen']: gr.update(visible=is_txt2img), | |
| ui_components['width_height_row_imagegen']: gr.update(visible=is_txt2img), | |
| ui_components['denoise_row_imagegen']: gr.update(visible=(is_img2img or is_inpaint or is_hires_fix)), | |
| ui_components['denoise_imagegen']: gr.update(value=denoise_val), | |
| ui_components['grow_mask_by_imagegen']: gr.update(visible=is_inpaint), | |
| ui_components['outpaint_pads_col_imagegen']: gr.update(visible=is_outpaint), | |
| ui_components['hires_upscaler_row_imagegen']: gr.update(visible=is_hires_fix), | |
| ui_components['run_imagegen']: gr.update(value=run_text), | |
| ui_components['result_imagegen']: gr.update(columns=gallery_cols, height=gallery_height), | |
| } | |
| # Re-evaluate feature accordion visibility based on task + architecture intersection | |
| type_map = {'Txt2Img': 'txt2img', 'Img2Img': 'img2img', 'Inpaint': 'inpaint', 'Outpaint': 'outpaint', 'Hires. Fix': 'hires_fix'} | |
| current_task = type_map.get(type_val, 'txt2img') | |
| m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") if model_name else "SDXL" | |
| architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) | |
| arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", "")) | |
| arch_enabled_chains = FEATURES_CONFIG.get(arch_model_type, {}).get('enabled_chains', []) | |
| task_enabled_chains = TASK_FEATURES_CONFIG.get(current_task, {}).get('enabled_chains', []) | |
| enabled_chains = [c for c in arch_enabled_chains if c in task_enabled_chains] | |
| prefix = 'imagegen' | |
| accordion_chain_map = { | |
| f'lora_accordion_{prefix}': 'lora', | |
| f'controlnet_accordion_{prefix}': 'controlnet', | |
| f'ipadapter_accordion_{prefix}': 'ipadapter', | |
| f'sd3_ipadapter_accordion_{prefix}': 'sd3_ipadapter', | |
| f'flux1_ipadapter_accordion_{prefix}': 'flux1_ipadapter', | |
| f'style_accordion_{prefix}': 'style', | |
| f'embedding_accordion_{prefix}': 'embedding', | |
| f'conditioning_accordion_{prefix}': 'conditioning', | |
| f'reference_latent_accordion_{prefix}': 'reference_latent', | |
| f'hidream_o1_reference_accordion_{prefix}': 'hidream_o1_reference', | |
| f'sensenova_reference_accordion_{prefix}': 'sensenova_reference', | |
| f'joyai_reference_accordion_{prefix}': 'joyai_image', | |
| f'krea2_identity_edit_accordion_{prefix}': 'krea2_identity_edit', | |
| f'krea2_reference_edit_accordion_{prefix}': 'krea2_style_reference', | |
| f'qwen_image_edit_accordion_{prefix}': 'qwen_image_edit', | |
| f'reference_image_accordion_{prefix}': 'reference_image', | |
| f'qwen_image_2_1_prompt_enhancer_accordion_{prefix}': 'qwen_image_2_1_prompt_enhancer', | |
| f'ming_image_prompt_enhancer_accordion_{prefix}': 'ming_image_prompt_enhancer', | |
| f'pid_accordion_{prefix}': 'pid', | |
| f'vae_accordion_{prefix}': 'vae', | |
| } | |
| for comp_key, chain_name in accordion_chain_map.items(): | |
| comp = ui_components.get(comp_key) | |
| if comp: | |
| updates[comp] = gr.update(visible=(chain_name in enabled_chains)) | |
| return updates | |
| type_change_outputs = [ | |
| ui_components['image_input_col_imagegen'], | |
| ui_components['input_image_imagegen'], | |
| ui_components['inpaint_box_imagegen'], | |
| ui_components['prompt_imagegen'], | |
| ui_components['neg_prompt_imagegen'], | |
| ui_components['aspect_ratio_row_imagegen'], | |
| ui_components['width_height_row_imagegen'], | |
| ui_components['denoise_row_imagegen'], | |
| ui_components['denoise_imagegen'], | |
| ui_components['grow_mask_by_imagegen'], | |
| ui_components['outpaint_pads_col_imagegen'], | |
| ui_components['hires_upscaler_row_imagegen'], | |
| ui_components['run_imagegen'], | |
| ui_components['result_imagegen'], | |
| ] | |
| # Add feature accordion outputs for task-based visibility | |
| accordion_keys = [ | |
| 'lora_accordion_imagegen', 'controlnet_accordion_imagegen', | |
| 'ipadapter_accordion_imagegen', | |
| 'sd3_ipadapter_accordion_imagegen', 'flux1_ipadapter_accordion_imagegen', | |
| 'style_accordion_imagegen', 'embedding_accordion_imagegen', | |
| 'conditioning_accordion_imagegen', 'reference_latent_accordion_imagegen', | |
| 'hidream_o1_reference_accordion_imagegen', 'sensenova_reference_accordion_imagegen', 'joyai_reference_accordion_imagegen', | |
| 'krea2_identity_edit_accordion_imagegen', 'krea2_reference_edit_accordion_imagegen', | |
| 'qwen_image_edit_accordion_imagegen', | |
| 'reference_image_accordion_imagegen', | |
| 'qwen_image_2_1_prompt_enhancer_accordion_imagegen', | |
| 'ming_image_prompt_enhancer_accordion_imagegen', | |
| 'pid_accordion_imagegen', 'vae_accordion_imagegen', | |
| ] | |
| for key in accordion_keys: | |
| if key in ui_components: | |
| type_change_outputs.append(ui_components[key]) | |
| ui_components['type_imagegen'].change( | |
| fn=on_type_change, | |
| inputs=[ui_components['type_imagegen'], ui_components['base_model_imagegen']], | |
| outputs=type_change_outputs, | |
| show_progress=False | |
| ) | |
| # Fullscreen view toggle for imagegen | |
| if 'view_mode_imagegen' in ui_components: | |
| def toggle_imagegen_fullscreen_view(view_mode): | |
| is_fullscreen = (view_mode == "Fullscreen View") | |
| other_elements_visible = not is_fullscreen | |
| editor_height = 800 if is_fullscreen else 272 | |
| updates = { | |
| ui_components['type_imagegen']: gr.update(visible=other_elements_visible), | |
| ui_components['prompts_col_imagegen']: gr.update(visible=other_elements_visible), | |
| ui_components['params_and_gallery_row_imagegen']: gr.update(visible=other_elements_visible), | |
| ui_components['accordion_wrapper_imagegen']: gr.update(visible=other_elements_visible), | |
| ui_components['input_image_dict_imagegen']: gr.update(height=editor_height), | |
| } | |
| model_and_run_rows = ui_components.get('model_and_run_row_imagegen', []) | |
| for row in model_and_run_rows: | |
| updates[row] = gr.update(visible=other_elements_visible) | |
| return updates | |
| output_components = [ui_components['type_imagegen']] | |
| model_and_run_rows = ui_components.get('model_and_run_row_imagegen', []) | |
| if isinstance(model_and_run_rows, list): | |
| output_components.extend(model_and_run_rows) | |
| else: | |
| output_components.append(model_and_run_rows) | |
| output_components.extend([ | |
| ui_components['prompts_col_imagegen'], | |
| ui_components['params_and_gallery_row_imagegen'], | |
| ui_components['accordion_wrapper_imagegen'], | |
| ui_components['input_image_dict_imagegen'] | |
| ]) | |
| ui_components['view_mode_imagegen'].change( | |
| fn=toggle_imagegen_fullscreen_view, | |
| inputs=[ui_components['view_mode_imagegen']], | |
| outputs=output_components, | |
| show_progress=False | |
| ) | |
| if 'view_mode_inpaint' in ui_components: | |
| def toggle_inpaint_fullscreen_view(view_mode): | |
| is_fullscreen = (view_mode == "Fullscreen View") | |
| other_elements_visible = not is_fullscreen | |
| editor_height = 800 if is_fullscreen else 272 | |
| updates = { | |
| ui_components['prompts_column_inpaint']: gr.update(visible=other_elements_visible), | |
| ui_components['params_and_gallery_row_inpaint']: gr.update(visible=other_elements_visible), | |
| ui_components['accordion_wrapper_inpaint']: gr.update(visible=other_elements_visible), | |
| ui_components['input_image_dict_inpaint']: gr.update(height=editor_height), | |
| } | |
| model_and_run_rows = ui_components.get('model_and_run_row_inpaint', []) | |
| for row in model_and_run_rows: | |
| updates[row] = gr.update(visible=other_elements_visible) | |
| return updates | |
| output_components = [] | |
| model_and_run_rows = ui_components.get('model_and_run_row_inpaint', []) | |
| if isinstance(model_and_run_rows, list): | |
| output_components.extend(model_and_run_rows) | |
| else: | |
| output_components.append(model_and_run_rows) | |
| output_components.extend([ | |
| ui_components['prompts_column_inpaint'], | |
| ui_components['params_and_gallery_row_inpaint'], | |
| ui_components['accordion_wrapper_inpaint'], | |
| ui_components['input_image_dict_inpaint'] | |
| ]) | |
| ui_components['view_mode_inpaint'].change( | |
| fn=toggle_inpaint_fullscreen_view, | |
| inputs=[ui_components['view_mode_inpaint']], | |
| outputs=output_components, | |
| show_progress=False | |
| ) | |
| all_load_outputs = [] | |
| for prefix in prefixes: | |
| if f'controlnet_types_{prefix}' in ui_components: | |
| all_load_outputs.extend(ui_components[f'controlnet_types_{prefix}']) | |
| all_load_outputs.extend(ui_components[f'controlnet_series_{prefix}']) | |
| all_load_outputs.extend(ui_components[f'controlnet_filepaths_{prefix}']) | |
| if f'ipadapter_final_preset_{prefix}' in ui_components: | |
| all_load_outputs.extend(ui_components[f'ipadapter_lora_strengths_{prefix}']) | |
| all_load_outputs.append(ui_components[f'ipadapter_final_preset_{prefix}']) | |
| all_load_outputs.append(ui_components[f'ipadapter_final_lora_strength_{prefix}']) | |
| if all_load_outputs: | |
| demo.load( | |
| fn=lambda: run_on_load(ui_components), | |
| outputs=all_load_outputs | |
| ) | |
| for prefix in prefixes: | |
| aspect_ratio_dropdown = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown') | |
| width_component = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width') | |
| height_component = ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height') | |
| model_dropdown = ui_components.get(f'base_model_{prefix}') | |
| if aspect_ratio_dropdown and width_component and height_component and model_dropdown: | |
| aspect_ratio_dropdown.change(fn=on_aspect_ratio_change, inputs=[aspect_ratio_dropdown, model_dropdown], outputs=[width_component, height_component], show_progress=False) |