diff --git a/README.md b/README.md index 45652b6215b267efdc2cefce67bce36b0a3abdec..b79d2b9d7f560e51f5b8a9d16e8f84a5d8d6a86c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ --- -title: ImageGen - FLUX.2 +title: ImageGen - FLUX.2-KV emoji: 🖼 colorFrom: purple colorTo: red diff --git a/app.py b/app.py index 997eeedce88dbb6f20b5d40af15f8583bcb50b92..bd7ce944da56842e1e0f9df10ecae6c0188f16ed 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,6 @@ import spaces import os import sys -import requests import site APP_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -45,106 +44,14 @@ def dummy_gpu_for_startup(): print("--- [GPU Startup] Startup check passed. ---") return "Startup check passed." -def handle_private_downloads(): - """ - Checks for a private_file_list.yaml, downloads required models using HF_TOKEN, - and then clears the token from the environment. - """ - import yaml - from huggingface_hub import hf_hub_download - from core.settings import ( - DIFFUSION_MODELS_DIR, TEXT_ENCODERS_DIR, VAE_DIR, CHECKPOINT_DIR, - LORA_DIR, CONTROLNET_DIR, MODEL_PATCHES_DIR, EMBEDDING_DIR - ) - - print("--- [Startup] Checking for private models to download... ---") - private_list_path = os.path.join(APP_DIR, 'yaml', 'private_file_list.yaml') - - if not os.path.exists(private_list_path): - print("--- [Startup] No private model list found. Skipping. ---") - if 'HF_TOKEN' in os.environ: - del os.environ['HF_TOKEN'] - print("--- [Startup] Cleared HF_TOKEN environment variable as it is no longer needed. ---") - print(f"--- [Startup] Verifying HF_TOKEN after clearing: {os.environ.get('HF_TOKEN')}") - return - - try: - with open(private_list_path, 'r', encoding='utf-8') as f: - private_files_config = yaml.safe_load(f) - - if not private_files_config or 'file' not in private_files_config: - print("--- [Startup] Private model list is empty or malformed. Skipping. ---") - return - - category_to_dir_map = { - "diffusion_models": DIFFUSION_MODELS_DIR, - "text_encoders": TEXT_ENCODERS_DIR, - "vae": VAE_DIR, - "checkpoints": CHECKPOINT_DIR, - "loras": LORA_DIR, - "controlnet": CONTROLNET_DIR, - "model_patches": MODEL_PATCHES_DIR, - "embeddings": EMBEDDING_DIR, - } - - files_to_download = [] - for category, files in private_files_config.get('file', {}).items(): - dest_dir = category_to_dir_map.get(category) - if not dest_dir: - print(f"--- [Startup] ⚠️ Unknown category '{category}' in private_file_list.yaml. Skipping. ---") - continue - - if isinstance(files, list): - for file_info in files: - files_to_download.append((file_info, dest_dir)) - - if not files_to_download: - print("--- [Startup] No private models configured for download. ---") - return - - print(f"--- [Startup] Found {len(files_to_download)} private model(s) to download. Using HF_TOKEN if available. ---") - - for file_info, dest_dir in files_to_download: - filename = file_info.get("filename") - repo_id = file_info.get("repo_id") - repo_path = file_info.get("repository_file_path", filename) - - if not all([filename, repo_id]): - print(f"--- [Startup] ⚠️ Skipping malformed entry in private_file_list.yaml: {file_info} ---") - continue - - dest_path = os.path.join(dest_dir, filename) - if os.path.lexists(dest_path): - print(f"--- [Startup] ✅ Model '{filename}' already exists. Skipping download. ---") - continue - - print(f"--- [Startup] ⏳ Downloading '{filename}' from repo '{repo_id}'... ---") - try: - cached_path = hf_hub_download(repo_id=repo_id, filename=repo_path) - os.makedirs(dest_dir, exist_ok=True) - os.symlink(cached_path, dest_path) - print(f"--- [Startup] ✅ Successfully downloaded and linked '{filename}'. ---") - except Exception as e: - print(f"--- [Startup] ❌ ERROR: Failed to download '{filename}': {e}") - print("--- [Startup] ❌ Please ensure your HF_TOKEN is set correctly and has access to the repository. ---") - - finally: - if 'HF_TOKEN' in os.environ: - del os.environ['HF_TOKEN'] - print("--- [Startup] ✅ Cleared HF_TOKEN environment variable. ---") - print(f"--- [Startup] Verifying HF_TOKEN after clearing: {os.environ.get('HF_TOKEN')}") - else: - print("--- [Startup] Note: HF_TOKEN environment variable was not set. Private downloads may fail without it. ---") def main(): from utils.app_utils import print_welcome_message from scripts import build_sage_attention + from comfy_integration import setup as setup_comfyui print_welcome_message() - # Handle downloads that require authentication first. - handle_private_downloads() - print("--- [Setup] Attempting to build and install SageAttention... ---") try: build_sage_attention.install_sage_attention() @@ -152,7 +59,9 @@ def main(): except Exception as e: print(f"--- [Setup] ❌ SageAttention installation failed: {e}. Continuing with default attention. ---") - + print("--- [Setup] Starting ComfyUI initialization ---") + setup_comfyui.initialize_comfyui() + print("--- [Setup] Reloading site-packages to detect newly installed packages... ---") try: site.main() @@ -160,52 +69,20 @@ def main(): except Exception as e: print(f"--- [Setup] ⚠️ Warning: Could not fully reload site-packages: {e} ---") - from comfy_integration import setup as setup_comfyui - from utils.app_utils import ( - build_preprocessor_model_map, - build_preprocessor_parameter_map - ) - from core import shared_state - from core.settings import ALL_MODEL_MAP, ALL_FILE_DOWNLOAD_MAP - - def check_all_model_urls_on_startup(): - print("--- [Setup] Checking all model URL validity (one-time check) ---") - for display_name, model_info in ALL_MODEL_MAP.items(): - _, components, _, _ = model_info - if not components: continue - - for filename in components.values(): - download_info = ALL_FILE_DOWNLOAD_MAP.get(filename, {}) - repo_id = download_info.get('repo_id') - if not repo_id: continue - - repo_file_path = download_info.get('repository_file_path', filename) - url = f"https://huggingface.co/{repo_id}/resolve/main/{repo_file_path}" - - try: - response = requests.head(url, timeout=5, allow_redirects=True) - if response.status_code >= 400: - print(f"❌ Invalid URL for '{display_name}' component '{filename}': {url} (Status: {response.status_code})") - shared_state.INVALID_MODEL_URLS[display_name] = True - break - except requests.RequestException as e: - print(f"❌ URL check failed for '{display_name}' component '{filename}': {e}") - shared_state.INVALID_MODEL_URLS[display_name] = True - break - print("--- [Setup] ✅ Finished checking model URLs. ---") + print("--- Initiating GPU Startup Check & SageAttention Patch ---") + try: + dummy_gpu_for_startup() + except Exception as e: + print(f"--- [GPU Startup] ⚠️ Warning: Startup check failed: {e} ---") + + from utils.app_utils import load_ipadapter_presets print("--- Starting Application Setup ---") - setup_comfyui.initialize_comfyui() + print("--- Loading IPAdapter presets ---") + load_ipadapter_presets() + print("--- ✅ IPAdapter setup complete. ---") - check_all_model_urls_on_startup() - - print("--- Building ControlNet preprocessor maps ---") - from core.generation_logic import build_reverse_map - build_reverse_map() - build_preprocessor_model_map() - build_preprocessor_parameter_map() - print("--- ✅ ControlNet preprocessor setup complete. ---") print("--- Environment configured. Proceeding with module imports. ---") from ui.layout import build_ui diff --git a/chain_injectors/controlnet_injector.py b/chain_injectors/controlnet_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..812df1b6a34c4c8bceb38b76baebc54254c06dcb --- /dev/null +++ b/chain_injectors/controlnet_injector.py @@ -0,0 +1,60 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + if ksampler_name not in assembler.node_map: + print(f"Warning: Target node '{ksampler_name}' for ControlNet chain not found. Skipping chain injection.") + return + + ksampler_id = assembler.node_map[ksampler_name] + + if 'positive' not in assembler.workflow[ksampler_id]['inputs'] or \ + 'negative' not in assembler.workflow[ksampler_id]['inputs']: + print(f"Warning: KSampler node '{ksampler_name}' is missing 'positive' or 'negative' inputs. Skipping ControlNet chain.") + return + + vae_source_str = chain_definition.get('vae_source') + if not vae_source_str: + print("Warning: 'vae_source' definition missing in the recipe for the ControlNet chain. Skipping.") + return + vae_node_name, vae_idx_str = vae_source_str.split(':') + if vae_node_name not in assembler.node_map: + print(f"Warning: VAE source node '{vae_node_name}' for ControlNet chain not found. Skipping.") + return + vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)] + + current_positive_connection = assembler.workflow[ksampler_id]['inputs']['positive'] + current_negative_connection = assembler.workflow[ksampler_id]['inputs']['negative'] + + for item_data in chain_items: + cn_loader_id = assembler._get_unique_id() + cn_loader_node = assembler._get_node_template("ControlNetLoader") + cn_loader_node['inputs']['control_net_name'] = item_data['control_net_name'] + assembler.workflow[cn_loader_id] = cn_loader_node + + image_loader_id = assembler._get_unique_id() + image_loader_node = assembler._get_node_template("LoadImage") + image_loader_node['inputs']['image'] = item_data['image'] + assembler.workflow[image_loader_id] = image_loader_node + + apply_cn_id = assembler._get_unique_id() + apply_cn_node = assembler._get_node_template(chain_definition['template']) + + apply_cn_node['inputs']['strength'] = item_data['strength'] + + apply_cn_node['inputs']['positive'] = current_positive_connection + apply_cn_node['inputs']['negative'] = current_negative_connection + apply_cn_node['inputs']['control_net'] = [cn_loader_id, 0] + apply_cn_node['inputs']['image'] = [image_loader_id, 0] + apply_cn_node['inputs']['vae'] = vae_connection + + assembler.workflow[apply_cn_id] = apply_cn_node + + current_positive_connection = [apply_cn_id, 0] + current_negative_connection = [apply_cn_id, 1] + + assembler.workflow[ksampler_id]['inputs']['positive'] = current_positive_connection + assembler.workflow[ksampler_id]['inputs']['negative'] = current_negative_connection + + print(f"ControlNet injector applied. KSampler inputs redirected through {len(chain_items)} ControlNet nodes.") \ No newline at end of file diff --git a/chain_injectors/diffsynth_controlnet_injector.py b/chain_injectors/diffsynth_controlnet_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..7c5a5a2ba15dfd7b54c281649ae36e0b3d2072ad --- /dev/null +++ b/chain_injectors/diffsynth_controlnet_injector.py @@ -0,0 +1,75 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + model_sampler_name = chain_definition.get('model_sampler_node') + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + + target_node_id = None + target_input_name = 'model' + + if model_sampler_name and model_sampler_name in assembler.node_map: + model_sampler_id = assembler.node_map[model_sampler_name] + if target_input_name in assembler.workflow[model_sampler_id]['inputs']: + target_node_id = model_sampler_id + print(f"ControlNet Model Patch injector targeting ModelSamplingAuraFlow node '{model_sampler_name}'.") + + if not target_node_id: + if ksampler_name in assembler.node_map: + ksampler_id = assembler.node_map[ksampler_name] + if target_input_name in assembler.workflow[ksampler_id]['inputs']: + target_node_id = ksampler_id + print(f"ControlNet Model Patch injector targeting KSampler node '{ksampler_name}'.") + else: + print(f"Warning: Neither ModelSamplingAuraFlow node '{model_sampler_name}' nor KSampler node '{ksampler_name}' found for ControlNet patch chain. Skipping.") + return + + if not target_node_id: + print(f"Warning: Could not find a valid 'model' input on target nodes. Skipping ControlNet patch chain.") + return + + current_model_connection = assembler.workflow[target_node_id]['inputs'][target_input_name] + + vae_source_str = chain_definition.get('vae_source') + vae_connection = None + if vae_source_str: + try: + vae_node_name, vae_idx_str = vae_source_str.split(':') + if vae_node_name in assembler.node_map: + vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)] + else: + print(f"Warning: VAE source node '{vae_node_name}' not found for ControlNet patch chain. VAE will not be connected.") + except ValueError: + print(f"Warning: Invalid 'vae_source' format '{vae_source_str}' for ControlNet patch chain. Expected 'node_name:index'. VAE will not be connected.") + else: + print(f"Warning: 'vae_source' not defined for ControlNet patch chain definition. VAE may not be connected.") + + for item_data in chain_items: + patch_loader_id = assembler._get_unique_id() + patch_loader_node = assembler._get_node_template("ModelPatchLoader") + patch_loader_node['inputs']['name'] = item_data['control_net_name'] + assembler.workflow[patch_loader_id] = patch_loader_node + + image_loader_id = assembler._get_unique_id() + image_loader_node = assembler._get_node_template("LoadImage") + image_loader_node['inputs']['image'] = item_data['image'] + assembler.workflow[image_loader_id] = image_loader_node + + apply_cn_id = assembler._get_unique_id() + apply_cn_node = assembler._get_node_template(chain_definition['template']) + + apply_cn_node['inputs']['strength'] = item_data.get('strength', 1.0) + apply_cn_node['inputs']['model'] = current_model_connection + apply_cn_node['inputs']['model_patch'] = [patch_loader_id, 0] + apply_cn_node['inputs']['image'] = [image_loader_id, 0] + + if 'vae' in apply_cn_node['inputs'] and vae_connection: + apply_cn_node['inputs']['vae'] = vae_connection + + assembler.workflow[apply_cn_id] = apply_cn_node + + current_model_connection = [apply_cn_id, 0] + + assembler.workflow[target_node_id]['inputs'][target_input_name] = current_model_connection + + print(f"ControlNet Model Patch injector applied. Target 'model' input re-routed through {len(chain_items)} patch(es).") \ No newline at end of file diff --git a/chain_injectors/flux1_ipadapter_injector.py b/chain_injectors/flux1_ipadapter_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..66fa6cc32fb927a4572e32a4b66fe9d0d9feeb8d --- /dev/null +++ b/chain_injectors/flux1_ipadapter_injector.py @@ -0,0 +1,46 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + if ksampler_name not in assembler.node_map: + print(f"Warning: KSampler node '{ksampler_name}' not found for Flux1 IPAdapter chain. Skipping.") + return + + ksampler_id = assembler.node_map[ksampler_name] + + if 'model' not in assembler.workflow[ksampler_id]['inputs']: + print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping Flux1 IPAdapter chain.") + return + + current_model_connection = assembler.workflow[ksampler_id]['inputs']['model'] + + for item_data in chain_items: + image_loader_id = assembler._get_unique_id() + image_loader_node = assembler._get_node_template("LoadImage") + image_loader_node['inputs']['image'] = item_data['image'] + assembler.workflow[image_loader_id] = image_loader_node + + ipadapter_loader_id = assembler._get_unique_id() + ipadapter_loader_node = assembler._get_node_template("IPAdapterFluxLoader") + ipadapter_loader_node['inputs']['ipadapter'] = "ip-adapter.bin" + ipadapter_loader_node['inputs']['clip_vision'] = "google/siglip-so400m-patch14-384" + ipadapter_loader_node['inputs']['provider'] = "cuda" + assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node + + apply_ipa_id = assembler._get_unique_id() + apply_ipa_node = assembler._get_node_template("ApplyIPAdapterFlux") + + apply_ipa_node['inputs']['weight'] = item_data['weight'] + apply_ipa_node['inputs']['start_percent'] = item_data.get('start_percent', 0.0) + apply_ipa_node['inputs']['end_percent'] = item_data.get('end_percent', 0.6) + + apply_ipa_node['inputs']['model'] = current_model_connection + apply_ipa_node['inputs']['ipadapter_flux'] = [ipadapter_loader_id, 0] + apply_ipa_node['inputs']['image'] = [image_loader_id, 0] + + assembler.workflow[apply_ipa_id] = apply_ipa_node + current_model_connection = [apply_ipa_id, 0] + + assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection + print(f"Flux1 IPAdapter injector applied. KSampler model input re-routed through {len(chain_items)} IPAdapter(s).") \ No newline at end of file diff --git a/chain_injectors/ipadapter_injector.py b/chain_injectors/ipadapter_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..f30ddc22fae5f520e396445e15a5f84bcaf71a24 --- /dev/null +++ b/chain_injectors/ipadapter_injector.py @@ -0,0 +1,106 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + final_settings = {} + if chain_items and isinstance(chain_items[-1], dict) and chain_items[-1].get('is_final_settings'): + final_settings = chain_items.pop() + + if not chain_items: + return + + end_node_name = chain_definition.get('end') + if not end_node_name or end_node_name not in assembler.node_map: + print(f"Warning: Target node '{end_node_name}' for IPAdapter chain not found. Skipping chain injection.") + return + + end_node_id = assembler.node_map[end_node_name] + + if 'model' not in assembler.workflow[end_node_id]['inputs']: + print(f"Warning: Target node '{end_node_name}' is missing 'model' input. Skipping IPAdapter chain.") + return + + current_model_connection = assembler.workflow[end_node_id]['inputs']['model'] + + model_type = final_settings.get('model_type', 'sdxl') + megapixels = 1.05 if model_type == 'sdxl' else 0.39 + + pos_embed_outputs = [] + neg_embed_outputs = [] + + for i, item_data in enumerate(chain_items): + loader_type = 'FaceID' if 'FACEID' in item_data.get('preset', '') else 'Unified' + + loader_template_name = "IPAdapterUnifiedLoader" + if loader_type == 'FaceID': + loader_template_name = "IPAdapterUnifiedLoaderFaceID" + + image_loader_id = assembler._get_unique_id() + image_loader_node = assembler._get_node_template("LoadImage") + image_loader_node['inputs']['image'] = item_data['image'] + assembler.workflow[image_loader_id] = image_loader_node + + image_scaler_id = assembler._get_unique_id() + image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels") + image_scaler_node['inputs']['image'] = [image_loader_id, 0] + image_scaler_node['inputs']['megapixels'] = megapixels + image_scaler_node['inputs']['upscale_method'] = "lanczos" + assembler.workflow[image_scaler_id] = image_scaler_node + + ipadapter_loader_id = assembler._get_unique_id() + ipadapter_loader_node = assembler._get_node_template(loader_template_name) + ipadapter_loader_node['inputs']['model'] = current_model_connection + ipadapter_loader_node['inputs']['preset'] = item_data['preset'] + if loader_type == 'FaceID': + ipadapter_loader_node['inputs']['lora_strength'] = item_data.get('lora_strength', 0.6) + assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node + + encoder_id = assembler._get_unique_id() + encoder_node = assembler._get_node_template("IPAdapterEncoder") + encoder_node['inputs']['weight'] = item_data['weight'] + encoder_node['inputs']['ipadapter'] = [ipadapter_loader_id, 1] + encoder_node['inputs']['image'] = [image_scaler_id, 0] + assembler.workflow[encoder_id] = encoder_node + + pos_embed_outputs.append([encoder_id, 0]) + neg_embed_outputs.append([encoder_id, 1]) + + pos_combiner_id = assembler._get_unique_id() + pos_combiner_node = assembler._get_node_template("IPAdapterCombineEmbeds") + pos_combiner_node['inputs']['method'] = final_settings.get('final_combine_method', 'concat') + for i, conn in enumerate(pos_embed_outputs): + pos_combiner_node['inputs'][f'embed{i+1}'] = conn + assembler.workflow[pos_combiner_id] = pos_combiner_node + + neg_combiner_id = assembler._get_unique_id() + neg_combiner_node = assembler._get_node_template("IPAdapterCombineEmbeds") + neg_combiner_node['inputs']['method'] = final_settings.get('final_combine_method', 'concat') + for i, conn in enumerate(neg_embed_outputs): + neg_combiner_node['inputs'][f'embed{i+1}'] = conn + assembler.workflow[neg_combiner_id] = neg_combiner_node + + final_loader_type = 'FaceID' if 'FACEID' in final_settings.get('final_preset', '') else 'Unified' + final_loader_template_name = "IPAdapterUnifiedLoader" + if final_loader_type == 'FaceID': + final_loader_template_name = "IPAdapterUnifiedLoaderFaceID" + + final_loader_id = assembler._get_unique_id() + final_loader_node = assembler._get_node_template(final_loader_template_name) + final_loader_node['inputs']['model'] = current_model_connection + final_loader_node['inputs']['preset'] = final_settings.get('final_preset', 'STANDARD (medium strength)') + if final_loader_type == 'FaceID': + final_loader_node['inputs']['lora_strength'] = final_settings.get('final_lora_strength', 0.6) + assembler.workflow[final_loader_id] = final_loader_node + + apply_embeds_id = assembler._get_unique_id() + apply_embeds_node = assembler._get_node_template("IPAdapterEmbeds") + apply_embeds_node['inputs']['weight'] = final_settings.get('final_weight', 1.0) + apply_embeds_node['inputs']['embeds_scaling'] = final_settings.get('final_embeds_scaling', 'V only') + apply_embeds_node['inputs']['model'] = [final_loader_id, 0] + apply_embeds_node['inputs']['ipadapter'] = [final_loader_id, 1] + apply_embeds_node['inputs']['pos_embed'] = [pos_combiner_id, 0] + apply_embeds_node['inputs']['neg_embed'] = [neg_combiner_id, 0] + assembler.workflow[apply_embeds_id] = apply_embeds_node + + assembler.workflow[end_node_id]['inputs']['model'] = [apply_embeds_id, 0] + print(f"IPAdapter injector applied. Redirected '{end_node_name}' model input through {len(chain_items)} reference images.") \ No newline at end of file diff --git a/chain_injectors/newbie_lora_injector.py b/chain_injectors/newbie_lora_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..6c13e8724a9b4c4fd4d6c8f32c1b0752c4029c9f --- /dev/null +++ b/chain_injectors/newbie_lora_injector.py @@ -0,0 +1,63 @@ +from copy import deepcopy + +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + output_map = chain_definition.get('output_map', {}) + current_connections = {} + for key, type_name in output_map.items(): + if ':' in str(key): + node_name, idx_str = key.split(':') + if node_name not in assembler.node_map: + print(f"Warning: [NewBie LoRA Injector] Node '{node_name}' in chain's output_map not found. Skipping.") + continue + node_id = assembler.node_map[node_name] + start_output_idx = int(idx_str) + current_connections[type_name] = [node_id, start_output_idx] + else: + print(f"Warning: [NewBie LoRA Injector] output_map key '{key}' is not in 'node:index' format. Skipping this connection.") + + template_name = chain_definition.get('template') + if not template_name: + print(f"Warning: [NewBie LoRA Injector] No 'template' defined for chain. Skipping.") + return + + for item_data in chain_items: + template = assembler._get_node_template(template_name) + node_data = deepcopy(template) + + node_data['inputs']['lora_name'] = item_data.get('lora_name') + node_data['inputs']['strength'] = item_data.get('strength_model', 1.0) + node_data['inputs']['enabled'] = True + + if 'model' in current_connections: + node_data['inputs']['model'] = current_connections['model'] + if 'clip' in current_connections: + node_data['inputs']['clip'] = current_connections['clip'] + + new_node_id = assembler._get_unique_id() + assembler.workflow[new_node_id] = node_data + + current_connections['model'] = [new_node_id, 0] + current_connections['clip'] = [new_node_id, 1] + + end_input_map = chain_definition.get('end_input_map', {}) + for type_name, targets in end_input_map.items(): + if type_name in current_connections: + if not isinstance(targets, list): + targets = [targets] + + for target_str in targets: + try: + end_node_name, end_input_name = target_str.split(':') + if end_node_name in assembler.node_map: + end_node_id = assembler.node_map[end_node_name] + assembler.workflow[end_node_id]['inputs'][end_input_name] = current_connections[type_name] + else: + print(f"Warning: [NewBie LoRA Injector] End node '{end_node_name}' for dynamic chain not found. Skipping connection.") + except ValueError: + print(f"Warning: [NewBie LoRA Injector] Invalid target format '{target_str}' in end_input_map. Skipping.") + + if chain_items: + print(f"NewBie LoRA injector applied. Re-routed model and clip through {len(chain_items)} LoRA(s).") \ No newline at end of file diff --git a/chain_injectors/reference_latent_injector.py b/chain_injectors/reference_latent_injector.py index e5746fc1fb4fe1bb971506b20074d850d0019a19..2b5becbfef4f60842ecf3af1b977a6e93b7c55a4 100644 --- a/chain_injectors/reference_latent_injector.py +++ b/chain_injectors/reference_latent_injector.py @@ -2,15 +2,78 @@ def inject(assembler, chain_definition, chain_items): if not chain_items: return - ksampler_name = chain_definition.get('ksampler_node', 'ksampler') - flux_guidance_name = chain_definition.get('flux_guidance_node') + guider_node_name = chain_definition.get('guider_node') + guider_target_inputs = chain_definition.get('guider_target_inputs', []) + start_connections_map = chain_definition.get('start_connections', {}) vae_node_name = chain_definition.get('vae_node', 'vae_loader') + if guider_node_name and guider_node_name in assembler.node_map and guider_target_inputs: + guider_id = assembler.node_map[guider_node_name] + if vae_node_name not in assembler.node_map: + print(f"Warning: VAE node '{vae_node_name}' not found for Guider chain. Skipping.") + return + vae_node_id = assembler.node_map[vae_node_name] + + print(f"ReferenceLatent injector targeting DualCFGGuider node '{guider_node_name}'.") + + current_connections = {} + for target_input in guider_target_inputs: + conn_str = start_connections_map.get(target_input) + if not conn_str: + print(f"Warning: No start connection defined for '{target_input}' in Guider chain. Skipping this input.") + continue + try: + node_name, idx_str = conn_str.split(':') + node_id = assembler.node_map[node_name] + current_connections[target_input] = [node_id, int(idx_str)] + except (ValueError, KeyError): + print(f"Warning: Invalid start connection '{conn_str}' for '{target_input}'. Skipping.") + + encoded_latents = [] + for i, img_filename in enumerate(chain_items): + load_id = assembler._get_unique_id() + load_node = assembler._get_node_template("LoadImage") + load_node['inputs']['image'] = img_filename + assembler.workflow[load_id] = load_node + + scale_id = assembler._get_unique_id() + scale_node = assembler._get_node_template("ImageScaleToTotalPixels") + scale_node['inputs']['megapixels'] = 1.0 + scale_node['inputs']['upscale_method'] = "lanczos" + scale_node['inputs']['image'] = [load_id, 0] + assembler.workflow[scale_id] = scale_node + + vae_encode_id = assembler._get_unique_id() + vae_encode_node = assembler._get_node_template("VAEEncode") + vae_encode_node['inputs']['pixels'] = [scale_id, 0] + vae_encode_node['inputs']['vae'] = [vae_node_id, 0] + assembler.workflow[vae_encode_id] = vae_encode_node + encoded_latents.append([vae_encode_id, 0]) + + for target_input_name, start_connection in current_connections.items(): + current_chain_head = start_connection + for i, latent_conn in enumerate(encoded_latents): + ref_latent_id = assembler._get_unique_id() + ref_latent_node = assembler._get_node_template("ReferenceLatent") + ref_latent_node['inputs']['conditioning'] = current_chain_head + ref_latent_node['inputs']['latent'] = latent_conn + ref_latent_node['_meta']['title'] = f"{target_input_name} RefLatent {i+1}" + assembler.workflow[ref_latent_id] = ref_latent_node + current_chain_head = [ref_latent_id, 0] + + assembler.workflow[guider_id]['inputs'][target_input_name] = current_chain_head + print(f" - Input '{target_input_name}' of node '{guider_node_name}' re-routed through {len(chain_items)} reference images.") + + return + + flux_guidance_name = chain_definition.get('flux_guidance_node') + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + if ksampler_name not in assembler.node_map: - print(f"Warning: [ReferenceLatent] KSampler node '{ksampler_name}' not found. Skipping.") + print(f"Warning: KSampler node '{ksampler_name}' not found for ReferenceLatent chain. Skipping.") return if vae_node_name not in assembler.node_map: - print(f"Warning: [ReferenceLatent] VAE loader node '{vae_node_name}' not found. Skipping.") + print(f"Warning: VAE loader node '{vae_node_name}' not found for ReferenceLatent chain. Skipping.") return ksampler_id = assembler.node_map[ksampler_name] @@ -23,44 +86,72 @@ def inject(assembler, chain_definition, chain_items): if 'conditioning' in assembler.workflow[flux_guidance_id]['inputs']: pos_target_node_id = flux_guidance_id pos_target_input_name = 'conditioning' - print(f"ReferenceLatent injector targeting FluxGuidance node '{flux_guidance_name}'.") + print(f"ReferenceLatent injector targeting FluxGuidance node '{flux_guidance_name}' for positive chain.") if not pos_target_node_id: if 'positive' in assembler.workflow[ksampler_id]['inputs']: pos_target_node_id = ksampler_id pos_target_input_name = 'positive' - print(f"ReferenceLatent injector targeting KSampler node '{ksampler_name}'.") + print(f"ReferenceLatent injector targeting KSampler node '{ksampler_name}' for positive chain.") else: - print(f"Warning: [ReferenceLatent] Could not find a valid positive injection point. Skipping.") + print(f"Warning: Could not find a valid positive injection point for ReferenceLatent chain. Skipping.") return current_pos_conditioning = assembler.workflow[pos_target_node_id]['inputs'][pos_target_input_name] - for i, img_filename in enumerate(chain_items): - if not img_filename or not isinstance(img_filename, str): - continue + neg_target_node_id = ksampler_id + neg_target_input_name = 'negative' + if 'negative' not in assembler.workflow[neg_target_node_id]['inputs']: + print(f"Warning: KSampler node '{ksampler_name}' has no 'negative' input. Skipping negative ReferenceLatent chain.") + neg_target_node_id = None + + current_neg_conditioning = None + if neg_target_node_id: + current_neg_conditioning = assembler.workflow[neg_target_node_id]['inputs'][neg_target_input_name] + for i, img_filename in enumerate(chain_items): load_id = assembler._get_unique_id() load_node = assembler._get_node_template("LoadImage") load_node['inputs']['image'] = img_filename + load_node['_meta']['title'] = f"Load Reference Image {i+1}" assembler.workflow[load_id] = load_node + scale_id = assembler._get_unique_id() + scale_node = assembler._get_node_template("ImageScaleToTotalPixels") + scale_node['inputs']['megapixels'] = 1.0 + scale_node['inputs']['upscale_method'] = "lanczos" + scale_node['inputs']['image'] = [load_id, 0] + scale_node['_meta']['title'] = f"Scale Reference {i+1}" + assembler.workflow[scale_id] = scale_node + vae_encode_id = assembler._get_unique_id() vae_encode_node = assembler._get_node_template("VAEEncode") - vae_encode_node['inputs']['pixels'] = [load_id, 0] + vae_encode_node['inputs']['pixels'] = [scale_id, 0] vae_encode_node['inputs']['vae'] = [vae_node_id, 0] + vae_encode_node['_meta']['title'] = f"VAE Encode Reference {i+1}" assembler.workflow[vae_encode_id] = vae_encode_node latent_conn = [vae_encode_id, 0] - ref_latent_id = assembler._get_unique_id() - ref_latent_node = assembler._get_node_template("ReferenceLatent") - ref_latent_node['inputs']['conditioning'] = current_pos_conditioning - ref_latent_node['inputs']['latent'] = latent_conn - assembler.workflow[ref_latent_id] = ref_latent_node - - current_pos_conditioning = [ref_latent_id, 0] + pos_ref_latent_id = assembler._get_unique_id() + pos_ref_latent_node = assembler._get_node_template("ReferenceLatent") + pos_ref_latent_node['inputs']['conditioning'] = current_pos_conditioning + pos_ref_latent_node['inputs']['latent'] = latent_conn + pos_ref_latent_node['_meta']['title'] = f"Positive ReferenceLatent {i+1}" + assembler.workflow[pos_ref_latent_id] = pos_ref_latent_node + current_pos_conditioning = [pos_ref_latent_id, 0] + + if neg_target_node_id: + neg_ref_latent_id = assembler._get_unique_id() + neg_ref_latent_node = assembler._get_node_template("ReferenceLatent") + neg_ref_latent_node['inputs']['conditioning'] = current_neg_conditioning + neg_ref_latent_node['inputs']['latent'] = latent_conn + neg_ref_latent_node['_meta']['title'] = f"Negative ReferenceLatent {i+1}" + assembler.workflow[neg_ref_latent_id] = neg_ref_latent_node + current_neg_conditioning = [neg_ref_latent_id, 0] assembler.workflow[pos_target_node_id]['inputs'][pos_target_input_name] = current_pos_conditioning + if neg_target_node_id: + assembler.workflow[neg_target_node_id]['inputs'][neg_target_input_name] = current_neg_conditioning - print(f"ReferenceLatent injector applied. Re-routed inputs through {len(chain_items)} reference image(s).") \ No newline at end of file + print(f"ReferenceLatent injector applied. Re-routed inputs through {len(chain_items)} reference images.") \ No newline at end of file diff --git a/chain_injectors/sd3_ipadapter_injector.py b/chain_injectors/sd3_ipadapter_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..2b7a9846647adb7ce1c2c2402ffb56951fa7be7d --- /dev/null +++ b/chain_injectors/sd3_ipadapter_injector.py @@ -0,0 +1,66 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + if ksampler_name not in assembler.node_map: + print(f"Warning: KSampler node '{ksampler_name}' not found for SD3 IPAdapter chain. Skipping.") + return + + ksampler_id = assembler.node_map[ksampler_name] + + if 'model' not in assembler.workflow[ksampler_id]['inputs']: + print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping SD3 IPAdapter chain.") + return + + current_model_connection = assembler.workflow[ksampler_id]['inputs']['model'] + + clip_vision_loader_id = assembler._get_unique_id() + clip_vision_loader_node = assembler._get_node_template("CLIPVisionLoader") + clip_vision_loader_node['inputs']['clip_name'] = "sigclip_vision_patch14_384.safetensors" + assembler.workflow[clip_vision_loader_id] = clip_vision_loader_node + + ipadapter_loader_id = assembler._get_unique_id() + ipadapter_loader_node = assembler._get_node_template("IPAdapterSD3Loader") + ipadapter_loader_node['inputs']['ipadapter'] = "ip-adapter_sd35l_instantx.bin" + ipadapter_loader_node['inputs']['provider'] = "cuda" + assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node + + for item_data in chain_items: + image_loader_id = assembler._get_unique_id() + image_loader_node = assembler._get_node_template("LoadImage") + image_loader_node['inputs']['image'] = item_data['image'] + assembler.workflow[image_loader_id] = image_loader_node + + image_scaler_id = assembler._get_unique_id() + image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels") + image_scaler_node['inputs']['image'] = [image_loader_id, 0] + image_scaler_node['inputs']['upscale_method'] = 'nearest-exact' + image_scaler_node['inputs']['megapixels'] = 1.0 + assembler.workflow[image_scaler_id] = image_scaler_node + + clip_vision_encode_id = assembler._get_unique_id() + clip_vision_encode_node = assembler._get_node_template("CLIPVisionEncode") + clip_vision_encode_node['inputs']['crop'] = "center" + clip_vision_encode_node['inputs']['clip_vision'] = [clip_vision_loader_id, 0] + clip_vision_encode_node['inputs']['image'] = [image_scaler_id, 0] + assembler.workflow[clip_vision_encode_id] = clip_vision_encode_node + + apply_ipa_id = assembler._get_unique_id() + apply_ipa_node = assembler._get_node_template("ApplyIPAdapterSD3") + + apply_ipa_node['inputs']['weight'] = item_data.get('weight', 1.0) + apply_ipa_node['inputs']['start_percent'] = item_data.get('start_percent', 0.0) + apply_ipa_node['inputs']['end_percent'] = item_data.get('end_percent', 1.0) + + apply_ipa_node['inputs']['model'] = current_model_connection + apply_ipa_node['inputs']['ipadapter'] = [ipadapter_loader_id, 0] + apply_ipa_node['inputs']['image_embed'] = [clip_vision_encode_id, 0] + + assembler.workflow[apply_ipa_id] = apply_ipa_node + + current_model_connection = [apply_ipa_id, 0] + + assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection + + print(f"SD3 IPAdapter injector applied. KSampler model input re-routed through {len(chain_items)} IPAdapter(s).") \ No newline at end of file diff --git a/chain_injectors/style_injector.py b/chain_injectors/style_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..48d903404d4752a8f821a4c00956135d890cdac8 --- /dev/null +++ b/chain_injectors/style_injector.py @@ -0,0 +1,71 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + flux_guidance_name = chain_definition.get('flux_guidance_node') + ksampler_name = chain_definition.get('ksampler_node', 'ksampler') + + target_node_id = None + target_input_name = None + + if flux_guidance_name and flux_guidance_name in assembler.node_map: + flux_guidance_id = assembler.node_map[flux_guidance_name] + if 'conditioning' in assembler.workflow[flux_guidance_id]['inputs']: + target_node_id = flux_guidance_id + target_input_name = 'conditioning' + + if not target_node_id: + if ksampler_name in assembler.node_map: + ksampler_id = assembler.node_map[ksampler_name] + if 'positive' in assembler.workflow[ksampler_id]['inputs']: + target_node_id = ksampler_id + target_input_name = 'positive' + else: + return + + if not target_node_id: + return + + current_conditioning = assembler.workflow[target_node_id]['inputs'][target_input_name] + + style_model_loader_id = assembler._get_unique_id() + style_model_loader_node = assembler._get_node_template("StyleModelLoader") + style_model_loader_node['inputs']['style_model_name'] = "flux1-redux-dev.safetensors" + assembler.workflow[style_model_loader_id] = style_model_loader_node + + clip_vision_loader_id = assembler._get_unique_id() + clip_vision_loader_node = assembler._get_node_template("CLIPVisionLoader") + clip_vision_loader_node['inputs']['clip_name'] = "sigclip_vision_patch14_384.safetensors" + assembler.workflow[clip_vision_loader_id] = clip_vision_loader_node + + for item_data in chain_items: + image = item_data.get('image') + strength = item_data.get('strength', 1.0) + if not image or strength is None: + continue + + load_image_id = assembler._get_unique_id() + clip_vision_encode_id = assembler._get_unique_id() + style_apply_id = assembler._get_unique_id() + + load_image_node = assembler._get_node_template("LoadImage") + clip_vision_encode_node = assembler._get_node_template("CLIPVisionEncode") + style_apply_node = assembler._get_node_template("StyleModelApply") + + load_image_node['inputs']['image'] = image + clip_vision_encode_node['inputs']['crop'] = "center" + clip_vision_encode_node['inputs']['clip_vision'] = [clip_vision_loader_id, 0] + clip_vision_encode_node['inputs']['image'] = [load_image_id, 0] + + style_apply_node['inputs']['strength'] = strength + style_apply_node['inputs']['strength_type'] = "multiply" + style_apply_node['inputs']['conditioning'] = current_conditioning + style_apply_node['inputs']['style_model'] = [style_model_loader_id, 0] + style_apply_node['inputs']['clip_vision_output'] = [clip_vision_encode_id, 0] + + assembler.workflow[load_image_id] = load_image_node + assembler.workflow[clip_vision_encode_id] = clip_vision_encode_node + assembler.workflow[style_apply_id] = style_apply_node + current_conditioning = [style_apply_id, 0] + + assembler.workflow[target_node_id]['inputs'][target_input_name] = current_conditioning \ No newline at end of file diff --git a/chain_injectors/vae_injector.py b/chain_injectors/vae_injector.py new file mode 100644 index 0000000000000000000000000000000000000000..c96b1227d8101ee644a692c30c266c454fab6968 --- /dev/null +++ b/chain_injectors/vae_injector.py @@ -0,0 +1,30 @@ +def inject(assembler, chain_definition, chain_items): + if not chain_items: + return + + vae_name = chain_items[0] if isinstance(chain_items, list) else chain_items + if not vae_name or vae_name == "None": + return + + targets = chain_definition.get('targets', []) + if not targets: + return + + vae_loader_id = assembler._get_unique_id() + vae_loader_node = assembler._get_node_template("VAELoader") + vae_loader_node['inputs']['vae_name'] = vae_name + assembler.workflow[vae_loader_id] = vae_loader_node + + injected_count = 0 + for target_str in targets: + try: + node_name, input_name = target_str.split(':') + if node_name in assembler.node_map: + node_id = assembler.node_map[node_name] + assembler.workflow[node_id]['inputs'][input_name] = [vae_loader_id, 0] + injected_count += 1 + except ValueError: + print(f"Warning: Invalid VAE injector target format '{target_str}'. Expected 'node_name:input_name'.") + + if injected_count > 0: + print(f"VAE injector applied. Rerouted {injected_count} connection(s) to new VAELoader ({vae_name}).") \ No newline at end of file diff --git a/comfy_integration/nodes.py b/comfy_integration/nodes.py index 76ba407e74bfffa63585c1e3505b39ec408d6711..7c37329e6422ca315c6afe7848bdafe5072c068f 100644 --- a/comfy_integration/nodes.py +++ b/comfy_integration/nodes.py @@ -23,6 +23,11 @@ CLIPTextEncodeSDXL = NODE_CLASS_MAPPINGS['CLIPTextEncodeSDXL'] LoraLoader = NODE_CLASS_MAPPINGS['LoraLoader'] CLIPSetLastLayer = NODE_CLASS_MAPPINGS['CLIPSetLastLayer'] +if 'EmptyHunyuanImageLatent' in NODE_CLASS_MAPPINGS: + EmptyHunyuanImageLatent = NODE_CLASS_MAPPINGS['EmptyHunyuanImageLatent'] +else: + print("⚠️ Warning: 'EmptyHunyuanImageLatent' not found in NODE_CLASS_MAPPINGS. HunyuanImage txt2img may fail if this node is required.") + try: KSamplerNode = NODE_CLASS_MAPPINGS['KSampler'] SAMPLER_CHOICES = KSamplerNode.INPUT_TYPES()["required"]["sampler_name"][0] diff --git a/comfy_integration/setup.py b/comfy_integration/setup.py index 97f7215676e7bc56a474d708660dd4a3207dea65..17f34ccc583fee8cfadeff1ee6aae708a1af9ba3 100644 --- a/comfy_integration/setup.py +++ b/comfy_integration/setup.py @@ -39,14 +39,40 @@ def initialize_comfyui(): except OSError as e: print(f"⚠️ Could not remove temporary directory '{COMFYUI_TEMP_DIR}': {e}") + print("--- Cloning third-party extensions for ComfyUI ---") - controlnet_aux_path = os.path.join(APP_DIR, "custom_nodes", "comfyui_controlnet_aux") - if not os.path.exists(controlnet_aux_path): - os.system(f"git clone https://github.com/Fannovel16/comfyui_controlnet_aux.git {controlnet_aux_path}") - print("✅ comfyui_controlnet_aux extension cloned.") + + # 1. ComfyUI_IPAdapter_plus + ipadapter_plus_path = os.path.join(APP_DIR, "custom_nodes", "ComfyUI_IPAdapter_plus") + if not os.path.exists(ipadapter_plus_path): + os.system(f"git clone https://github.com/cubiq/ComfyUI_IPAdapter_plus.git {ipadapter_plus_path}") + print("✅ ComfyUI_IPAdapter_plus extension cloned.") else: - print("✅ comfyui_controlnet_aux extension already exists.") + print("✅ ComfyUI_IPAdapter_plus extension already exists.") + # 2. ComfyUI-InstantX-IPAdapter-SD3 + ipadapter_plus_path = os.path.join(APP_DIR, "custom_nodes", "ComfyUI-InstantX-IPAdapter-SD3") + if not os.path.exists(ipadapter_plus_path): + os.system(f"git clone https://github.com/Slickytail/ComfyUI-InstantX-IPAdapter-SD3.git {ipadapter_plus_path}") + print("✅ ComfyUI-InstantX-IPAdapter-SD3 extension cloned.") + else: + print("✅ ComfyUI-InstantX-IPAdapter-SD3 extension already exists.") + + # 3. ComfyUI-IPAdapter-Flux + ipadapter_flux_path = os.path.join(APP_DIR, "custom_nodes", "ComfyUI-IPAdapter-Flux") + if not os.path.exists(ipadapter_flux_path): + os.system(f"git clone https://github.com/Shakker-Labs/ComfyUI-IPAdapter-Flux.git {ipadapter_flux_path}") + print("✅ ComfyUI-IPAdapter-Flux extension cloned.") + else: + print("✅ ComfyUI-IPAdapter-Flux extension already exists.") + + # 4. ComfyUI-Newbie-Nodes + newbie_nodes_path = os.path.join(APP_DIR, "custom_nodes", "ComfyUI-Newbie-Nodes") + if not os.path.exists(newbie_nodes_path): + os.system(f"git clone https://github.com/NewBieAI-Lab/ComfyUI-Newbie-Nodes.git {newbie_nodes_path}") + print("✅ ComfyUI-Newbie-Nodes extension cloned.") + else: + print("✅ ComfyUI-Newbie-Nodes extension already exists.") print(f"✅ Current working directory is: {os.getcwd()}") @@ -55,13 +81,10 @@ def initialize_comfyui(): print("✅ ComfyUI initialized with default attention mechanism.") - os.makedirs(os.path.join(APP_DIR, CHECKPOINT_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, LORA_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, EMBEDDING_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, CONTROLNET_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, MODEL_PATCHES_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, DIFFUSION_MODELS_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, VAE_DIR), exist_ok=True) - os.makedirs(os.path.join(APP_DIR, TEXT_ENCODERS_DIR), exist_ok=True) + for dir_path in CATEGORY_TO_DIR_MAP.values(): + os.makedirs(os.path.join(APP_DIR, dir_path), exist_ok=True) + os.makedirs(os.path.join(APP_DIR, INPUT_DIR), exist_ok=True) + os.makedirs(os.path.join(APP_DIR, OUTPUT_DIR), exist_ok=True) + print("✅ All required model directories are present.") \ No newline at end of file diff --git a/core/generation_logic.py b/core/generation_logic.py index 4e6433741c40a2e2342dc8dfe632fbf5ac60951d..a09b0076b3d2261c7f32420c87d157f967876041 100644 --- a/core/generation_logic.py +++ b/core/generation_logic.py @@ -1,25 +1,10 @@ from typing import Any, Dict import gradio as gr -from core.pipelines.controlnet_preprocessor import ControlNetPreprocessorPipeline from core.pipelines.sd_image_pipeline import SdImagePipeline -controlnet_preprocessor_pipeline = ControlNetPreprocessorPipeline() sd_image_pipeline = SdImagePipeline() -def build_reverse_map(): - from nodes import NODE_DISPLAY_NAME_MAPPINGS - import core.pipelines.controlnet_preprocessor as cn_module - - if cn_module.REVERSE_DISPLAY_NAME_MAP is None: - cn_module.REVERSE_DISPLAY_NAME_MAP = {v: k for k, v in NODE_DISPLAY_NAME_MAPPINGS.items()} - if "Semantic Segmentor (legacy, alias for UniFormer)" not in cn_module.REVERSE_DISPLAY_NAME_MAP: - cn_module.REVERSE_DISPLAY_NAME_MAP["Semantic Segmentor (legacy, alias for UniFormer)"] = "SemSegPreprocessor" - - -def run_cn_preprocessor_entry(*args, **kwargs): - return controlnet_preprocessor_pipeline.run(*args, **kwargs) - def generate_image_wrapper(ui_inputs: dict, progress=gr.Progress(track_tqdm=True)): return sd_image_pipeline.run(ui_inputs=ui_inputs, progress=progress) \ No newline at end of file diff --git a/core/model_manager.py b/core/model_manager.py index 9363e729907bde9707d859315a7dadab4190ed36..a4b0d217883a31d017df8f3b00ec9dbb7b271531 100644 --- a/core/model_manager.py +++ b/core/model_manager.py @@ -1,9 +1,8 @@ import gc from typing import List import gradio as gr - -from core.settings import ALL_MODEL_MAP from utils.app_utils import _ensure_model_downloaded +from core.settings import ALL_MODEL_MAP class ModelManager: _instance = None @@ -21,25 +20,13 @@ class ModelManager: def ensure_models_downloaded(self, required_models: List[str], progress): print(f"--- [ModelManager] Ensuring models are downloaded: {required_models} ---") - - files_to_download = set() - for display_name in required_models: - if display_name in ALL_MODEL_MAP: - _, components, _, _ = ALL_MODEL_MAP[display_name] - for component_file in components.values(): - files_to_download.add(component_file) - - files_to_download = list(files_to_download) - total_files = len(files_to_download) - - for i, filename in enumerate(files_to_download): + for i, display_name in enumerate(required_models): if progress and hasattr(progress, '__call__'): - progress(i / total_files if total_files > 0 else 0, desc=f"Checking file: {filename}") + progress(i / max(len(required_models), 1), desc=f"Checking file: {display_name}") try: - _ensure_model_downloaded(filename, progress) + _ensure_model_downloaded(display_name, progress) except Exception as e: - raise gr.Error(f"Failed to download model component '{filename}'. Reason: {e}") - + raise gr.Error(f"Failed to download model '{display_name}'. Reason: {e}") print(f"--- [ModelManager] ✅ All required models are present on disk. ---") - + model_manager = ModelManager() \ No newline at end of file diff --git a/core/pipelines/controlnet_preprocessor.py b/core/pipelines/controlnet_preprocessor.py deleted file mode 100644 index bdfec36241e60425488b16bbc1e0bb14d39906ec..0000000000000000000000000000000000000000 --- a/core/pipelines/controlnet_preprocessor.py +++ /dev/null @@ -1,143 +0,0 @@ -from typing import Dict, Any, List -import imageio -import tempfile -import numpy as np -import torch -import gradio as gr -from PIL import Image -import spaces - -from .base_pipeline import BasePipeline -from comfy_integration.nodes import NODE_CLASS_MAPPINGS -from nodes import NODE_DISPLAY_NAME_MAPPINGS -from utils.app_utils import get_value_at_index - -REVERSE_DISPLAY_NAME_MAP = None -CPU_ONLY_PREPROCESSORS = { - "Binary Lines", "Canny Edge", "Color Pallete", "Fake Scribble Lines (aka scribble_hed)", - "Image Intensity", "Image Luminance", "Inpaint Preprocessor", "PyraCanny", "Scribble Lines", - "Scribble XDoG Lines", "Standard Lineart", "Content Shuffle", "Tile" -} - -def run_node_by_function_name(node_instance: Any, **kwargs) -> Any: - node_class = type(node_instance) - function_name = getattr(node_class, 'FUNCTION', None) - if not function_name: - raise AttributeError(f"Node class '{node_class.__name__}' is missing the required 'FUNCTION' attribute.") - execution_method = getattr(node_instance, function_name, None) - if not callable(execution_method): - raise AttributeError(f"Method '{function_name}' not found or not callable on node '{node_class.__name__}'.") - return execution_method(**kwargs) - -class ControlNetPreprocessorPipeline(BasePipeline): - def get_required_models(self, **kwargs) -> List[str]: - return [] - - def _gpu_logic( - self, pil_images: List[Image.Image], preprocessor_name: str, model_name: str, - params: Dict[str, Any], progress=gr.Progress(track_tqdm=True) - ) -> List[Image.Image]: - global REVERSE_DISPLAY_NAME_MAP - if REVERSE_DISPLAY_NAME_MAP is None: - raise RuntimeError("REVERSE_DISPLAY_NAME_MAP has not been initialized. `build_reverse_map` must be called on startup.") - - class_name = REVERSE_DISPLAY_NAME_MAP.get(preprocessor_name) - if not class_name or class_name not in NODE_CLASS_MAPPINGS: - raise ValueError(f"Preprocessor '{preprocessor_name}' not found.") - - preprocessor_instance = NODE_CLASS_MAPPINGS[class_name]() - call_args = {**params, 'ckpt_name': model_name} - - processed_pil_images = [] - total_frames = len(pil_images) - - for i, frame_pil in enumerate(pil_images): - progress(i / total_frames, desc=f"Processing frame {i+1}/{total_frames} with {preprocessor_name}...") - - frame_tensor = torch.from_numpy(np.array(frame_pil).astype(np.float32) / 255.0).unsqueeze(0) - - resolution_arg = {'resolution': max(frame_tensor.shape[2], frame_tensor.shape[3])} - - result_tuple = run_node_by_function_name( - preprocessor_instance, - image=frame_tensor, - **resolution_arg, - **call_args - ) - - processed_tensor = get_value_at_index(result_tuple, 0) - processed_np = (processed_tensor.squeeze(0).cpu().numpy().clip(0, 1) * 255.0).astype(np.uint8) - processed_pil_images.append(Image.fromarray(processed_np)) - - return processed_pil_images - - def run(self, input_type, image_input, video_input, preprocessor_name, model_name, zero_gpu_duration, *args, progress=gr.Progress(track_tqdm=True)): - from utils import app_utils - pil_images, is_video, fps = [], False, 30 - - progress(0, desc="Reading input file...") - if input_type == "Image": - if image_input is None: raise gr.Error("Please provide an input image.") - pil_images = [image_input] - elif input_type == "Video": - if video_input is None: raise gr.Error("Please provide an input video.") - try: - video_reader = imageio.get_reader(video_input) - meta = video_reader.get_meta_data() - fps = meta.get('fps', 30) - pil_images = [Image.fromarray(frame) for frame in video_reader] - is_video = True - video_reader.close() - except Exception as e: raise gr.Error(f"Failed to read video file: {e}") - else: - raise gr.Error("Invalid input type selected.") - - if not pil_images: raise gr.Error("Could not extract any frames from the input.") - - if app_utils.PREPROCESSOR_PARAMETER_MAP is None: - raise RuntimeError("Preprocessor parameter map is not built. Check startup logs.") - - params_config = app_utils.PREPROCESSOR_PARAMETER_MAP.get(preprocessor_name, []) - sliders_params = [p for p in params_config if p['type'] in ["INT", "FLOAT"]] - dropdown_params = [p for p in params_config if isinstance(p['type'], list)] - checkbox_params = [p for p in params_config if p['type'] == "BOOLEAN"] - ordered_params_config = sliders_params + dropdown_params + checkbox_params - param_names = [p['name'] for p in ordered_params_config] - provided_params = {param_names[i]: args[i] for i in range(len(param_names))} - - if preprocessor_name not in CPU_ONLY_PREPROCESSORS: - print(f"--- '{preprocessor_name}' requires GPU, requesting ZeroGPU. ---") - try: - processed_pil_images = self._execute_gpu_logic( - self._gpu_logic, - duration=zero_gpu_duration, - default_duration=60, - task_name=f"Preprocessor '{preprocessor_name}'", - pil_images=pil_images, - preprocessor_name=preprocessor_name, - model_name=model_name, - params=provided_params, - progress=progress - ) - except Exception as e: - import traceback; traceback.print_exc() - raise gr.Error(f"Failed to run preprocessor '{preprocessor_name}' on GPU: {e}") - else: - print(f"--- Running '{preprocessor_name}' on CPU, no ZeroGPU requested. ---") - try: - processed_pil_images = self._gpu_logic(pil_images, preprocessor_name, model_name, provided_params, progress=progress) - except Exception as e: - import traceback; traceback.print_exc() - raise gr.Error(f"Failed to run preprocessor '{preprocessor_name}' on CPU: {e}") - - if not processed_pil_images: raise gr.Error("Processing returned no frames.") - - progress(0.9, desc="Finalizing output...") - if is_video: - frames_np = [np.array(img) for img in processed_pil_images] - frames_tensor = torch.from_numpy(np.stack(frames_np)).to(torch.float32) / 255.0 - video_path = self._encode_video_from_frames(frames_tensor, fps, progress) - return [video_path] - else: - progress(1.0, desc="Done!") - return processed_pil_images \ No newline at end of file diff --git a/core/pipelines/sd_image_pipeline.py b/core/pipelines/sd_image_pipeline.py index c01f59d87428a72c50718eed84c6a584bc34c95c..c4bae29d55532de898e5776f2323c1dbd92d0472 100644 --- a/core/pipelines/sd_image_pipeline.py +++ b/core/pipelines/sd_image_pipeline.py @@ -11,12 +11,20 @@ import numpy as np from .base_pipeline import BasePipeline from core.settings import * from comfy_integration.nodes import * -from utils.app_utils import get_value_at_index, sanitize_prompt, get_lora_path, get_embedding_path, ensure_controlnet_model_downloaded, sanitize_filename +from utils.app_utils import get_value_at_index, sanitize_prompt, get_lora_path, get_embedding_path, ensure_controlnet_model_downloaded, ensure_ipadapter_models_downloaded, sanitize_filename from core.workflow_assembler import WorkflowAssembler class SdImagePipeline(BasePipeline): def get_required_models(self, model_display_name: str, **kwargs) -> List[str]: - return [model_display_name] + model_info = ALL_MODEL_MAP.get(model_display_name) + if not model_info: + return [model_display_name] + + path_or_components = model_info[1] + if isinstance(path_or_components, dict): + return [v for v in path_or_components.values() if v and v != "pixel_space"] + else: + return [model_display_name] def _topological_sort(self, workflow: Dict[str, Any]) -> List[str]: graph = defaultdict(list) @@ -47,7 +55,6 @@ class SdImagePipeline(BasePipeline): return sorted_nodes - def _execute_workflow(self, workflow: Dict[str, Any], initial_objects: Dict[str, Any]): with torch.no_grad(): computed_outputs = initial_objects @@ -119,7 +126,7 @@ class SdImagePipeline(BasePipeline): progress(0.4, desc="Executing workflow...") initial_objects = {} - + decoded_images_tensor = self._execute_workflow(workflow, initial_objects=initial_objects) output_images = [] @@ -135,6 +142,7 @@ class SdImagePipeline(BasePipeline): params_string = f"{ui_inputs['positive_prompt']}\nNegative prompt: {ui_inputs['negative_prompt']}\n" params_string += f"Steps: {ui_inputs['num_inference_steps']}, Sampler: {ui_inputs['sampler']}, Scheduler: {ui_inputs['scheduler']}, CFG scale: {ui_inputs['guidance_scale']}, Seed: {current_seed}, Size: {width_for_meta}x{height_for_meta}, Base Model: {model_display_name}" if ui_inputs['task_type'] != 'txt2img': params_string += f", Denoise: {ui_inputs['denoise']}" + if ui_inputs.get('clip_skip') and ui_inputs['clip_skip'] != 1: params_string += f", Clip skip: {abs(ui_inputs['clip_skip'])}" if loras_string: params_string += f", {loras_string}" pil_image.info = {'parameters': params_string.strip()} @@ -146,39 +154,46 @@ class SdImagePipeline(BasePipeline): progress(0, desc="Preparing models...") task_type = ui_inputs['task_type'] + model_display_name = ui_inputs['model_display_name'] + model_type = MODEL_TYPE_MAP.get(model_display_name, 'sdxl') + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + workflow_model_type = architectures_dict.get(model_type, {}).get("model_type", "sdxl") ui_inputs['positive_prompt'] = sanitize_prompt(ui_inputs.get('positive_prompt', '')) ui_inputs['negative_prompt'] = sanitize_prompt(ui_inputs.get('negative_prompt', '')) - required_models = self.get_required_models(model_display_name=ui_inputs['model_display_name']) - + if 'clip_skip' in ui_inputs and ui_inputs['clip_skip'] is not None: + ui_inputs['clip_skip'] = -int(ui_inputs['clip_skip']) + else: + ui_inputs['clip_skip'] = -1 + + required_models = self.get_required_models(model_display_name=model_display_name) self.model_manager.ensure_models_downloaded(required_models, progress=progress) lora_data = ui_inputs.get('lora_data', []) active_loras_for_gpu, active_loras_for_meta = [], [] if lora_data: sources, ids, scales, files = lora_data[0::4], lora_data[1::4], lora_data[2::4], lora_data[3::4] - for i, (source, lora_id, scale, _) in enumerate(zip(sources, ids, scales, files)): if scale > 0 and lora_id and lora_id.strip(): lora_filename = None if source == "File": lora_filename = sanitize_filename(lora_id) elif source == "Civitai": - local_path, status = get_lora_path(source, lora_id, ui_inputs['civitai_api_key'], progress) + local_path, status = get_lora_path(source, lora_id, os.environ.get("CIVITAI_API_KEY", ""), progress) if local_path: lora_filename = os.path.basename(local_path) else: raise gr.Error(f"Failed to prepare LoRA {lora_id}: {status}") if lora_filename: active_loras_for_gpu.append({"lora_name": lora_filename, "strength_model": scale, "strength_clip": scale}) active_loras_for_meta.append(f"{source} {lora_id}:{scale}") - + ui_inputs['denoise'] = 1.0 if task_type == 'img2img': ui_inputs['denoise'] = ui_inputs.get('img2img_denoise', 0.7) elif task_type == 'hires_fix': ui_inputs['denoise'] = ui_inputs.get('hires_denoise', 0.55) temp_files_to_clean = [] - if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR) if task_type == 'img2img': @@ -197,7 +212,6 @@ class SdImagePipeline(BasePipeline): raise gr.Error("Inpainting requires an input image and a drawn mask.") background_img = inpaint_dict['background'].convert("RGBA") - composite_mask_pil = Image.new('L', background_img.size, 0) for layer in inpaint_dict['layers']: if layer: @@ -211,7 +225,7 @@ class SdImagePipeline(BasePipeline): temp_file_path = os.path.join(INPUT_DIR, f"temp_inpaint_composite_{random.randint(1000, 9999)}.png") composite_image_with_mask.save(temp_file_path, "PNG") - ui_inputs['inpaint_image'] = os.path.basename(temp_file_path) + ui_inputs['input_image'] = os.path.basename(temp_file_path) temp_files_to_clean.append(temp_file_path) ui_inputs.pop('inpaint_mask', None) @@ -222,6 +236,9 @@ class SdImagePipeline(BasePipeline): input_image_pil.save(temp_file_path, "PNG") ui_inputs['input_image'] = os.path.basename(temp_file_path) temp_files_to_clean.append(temp_file_path) + + ui_inputs['megapixels'] = 0.25 + ui_inputs['grow_mask_by'] = ui_inputs.get('feathering', 10) elif task_type == 'hires_fix': input_image_pil = ui_inputs.get('hires_image') @@ -241,7 +258,7 @@ class SdImagePipeline(BasePipeline): if source == "File": emb_filename = sanitize_filename(emb_id) elif source == "Civitai": - local_path, status = get_embedding_path(source, emb_id, ui_inputs['civitai_api_key'], progress) + local_path, status = get_embedding_path(source, emb_id, os.environ.get("CIVITAI_API_KEY", ""), progress) if local_path: emb_filename = os.path.basename(local_path) else: raise gr.Error(f"Failed to prepare Embedding {emb_id}: {status}") @@ -255,20 +272,162 @@ class SdImagePipeline(BasePipeline): else: ui_inputs['positive_prompt'] = embedding_prompt_text + controlnet_data = ui_inputs.get('controlnet_data', []) + active_controlnets = [] + if controlnet_data: + (cn_images, _, _, cn_strengths, cn_filepaths) = [controlnet_data[i::5] for i in range(5)] + for i in range(len(cn_images)): + if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None": + ensure_controlnet_model_downloaded(cn_filepaths[i], progress) + if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR) + cn_temp_path = os.path.join(INPUT_DIR, f"temp_cn_{i}_{random.randint(1000, 9999)}.png") + cn_images[i].save(cn_temp_path, "PNG") + temp_files_to_clean.append(cn_temp_path) + active_controlnets.append({ + "image": os.path.basename(cn_temp_path), "strength": cn_strengths[i], + "start_percent": 0.0, "end_percent": 1.0, "control_net_name": cn_filepaths[i] + }) + + diffsynth_controlnet_data = ui_inputs.get('diffsynth_controlnet_data', []) + active_diffsynth_controlnets = [] + if diffsynth_controlnet_data: + (cn_images, _, _, cn_strengths, cn_filepaths) = [diffsynth_controlnet_data[i::5] for i in range(5)] + for i in range(len(cn_images)): + if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None": + ensure_controlnet_model_downloaded(cn_filepaths[i], progress) + + if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR) + cn_temp_path = os.path.join(INPUT_DIR, f"temp_diffsynth_cn_{i}_{random.randint(1000, 9999)}.png") + cn_images[i].save(cn_temp_path, "PNG") + temp_files_to_clean.append(cn_temp_path) + active_diffsynth_controlnets.append({ + "image": os.path.basename(cn_temp_path), "strength": cn_strengths[i], + "control_net_name": cn_filepaths[i] + }) + + ipadapter_data = ui_inputs.get('ipadapter_data', []) + active_ipadapters = [] + if ipadapter_data: + num_ipa_units = (len(ipadapter_data) - 5) // 3 + final_preset, final_weight, final_lora_strength, final_embeds_scaling, final_combine_method = ipadapter_data[-5:] + ipa_images, ipa_weights, ipa_lora_strengths = [ipadapter_data[i*num_ipa_units:(i+1)*num_ipa_units] for i in range(3)] + all_presets_to_download = set() + for i in range(num_ipa_units): + if ipa_images[i] and ipa_weights[i] > 0 and final_preset: + all_presets_to_download.add(final_preset) + if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR) + ipa_temp_path = os.path.join(INPUT_DIR, f"temp_ipa_{i}_{random.randint(1000, 9999)}.png") + ipa_images[i].save(ipa_temp_path, "PNG") + temp_files_to_clean.append(ipa_temp_path) + active_ipadapters.append({ + "image": os.path.basename(ipa_temp_path), "preset": final_preset, + "weight": ipa_weights[i], "lora_strength": ipa_lora_strengths[i] + }) + if active_ipadapters and final_preset: + all_presets_to_download.add(final_preset) + for preset in all_presets_to_download: + ensure_ipadapter_models_downloaded(preset, progress) + + model_type_key = 'sd15' if workflow_model_type == 'sd15' else 'sdxl' + if active_ipadapters: + active_ipadapters.append({ + 'is_final_settings': True, 'model_type': model_type_key, 'final_preset': final_preset, + 'final_weight': final_weight, 'final_lora_strength': final_lora_strength, + 'final_embeds_scaling': final_embeds_scaling, 'final_combine_method': final_combine_method + }) + + flux1_ipadapter_data = ui_inputs.get('flux1_ipadapter_data', []) + active_flux1_ipadapters = [] + if flux1_ipadapter_data: + num_units = len(flux1_ipadapter_data) // 4 + f_images = flux1_ipadapter_data[0*num_units : 1*num_units] + f_weights = flux1_ipadapter_data[1*num_units : 2*num_units] + f_starts = flux1_ipadapter_data[2*num_units : 3*num_units] + f_ends = flux1_ipadapter_data[3*num_units : 4*num_units] + for i in range(len(f_images)): + if f_images[i] and f_weights[i] > 0: + from utils.app_utils import _ensure_model_downloaded + for filename in ["ip-adapter.bin"]: + _ensure_model_downloaded(filename, progress) + + from huggingface_hub import snapshot_download + progress(0.5, desc="Caching HF SigLIP model...") + snapshot_download( + repo_id="google/siglip-so400m-patch14-384", + allow_patterns=["*.json", "*.safetensors", "*.txt"], + ignore_patterns=["*.msgpack", "*.h5", "*.bin"] + ) + + temp_path = os.path.join(INPUT_DIR, f"temp_fipa_{i}_{random.randint(1000, 9999)}.png") + f_images[i].save(temp_path, "PNG") + temp_files_to_clean.append(temp_path) + active_flux1_ipadapters.append({ + "image": os.path.basename(temp_path), + "weight": f_weights[i], "start_percent": f_starts[i], "end_percent": f_ends[i] + }) + + sd3_ipadapter_data = ui_inputs.get('sd3_ipadapter_chain', []) + active_sd3_ipadapters = [] + if sd3_ipadapter_data: + num_units = len(sd3_ipadapter_data) // 4 + s_images = sd3_ipadapter_data[0*num_units : 1*num_units] + s_weights = sd3_ipadapter_data[1*num_units : 2*num_units] + s_starts = sd3_ipadapter_data[2*num_units : 3*num_units] + s_ends = sd3_ipadapter_data[3*num_units : 4*num_units] + sd3_ipa_downloaded = False + for i in range(len(s_images)): + if s_images[i] and s_weights[i] > 0: + if not sd3_ipa_downloaded: + from utils.app_utils import ensure_sd3_ipadapter_models_downloaded + ensure_sd3_ipadapter_models_downloaded(progress) + sd3_ipa_downloaded = True + temp_path = os.path.join(INPUT_DIR, f"temp_s3ipa_{i}_{random.randint(1000, 9999)}.png") + s_images[i].save(temp_path, "PNG") + temp_files_to_clean.append(temp_path) + active_sd3_ipadapters.append({ + "image": os.path.basename(temp_path), + "weight": s_weights[i], "start_percent": s_starts[i], "end_percent": s_ends[i] + }) + + style_data = ui_inputs.get('style_data', []) + active_styles = [] + if style_data: + num_units = len(style_data) // 2 + st_images = style_data[0*num_units : 1*num_units] + st_strengths = style_data[1*num_units : 2*num_units] + for i in range(len(st_images)): + if st_images[i] and st_strengths[i] > 0: + from utils.app_utils import _ensure_model_downloaded + _ensure_model_downloaded("sigclip_vision_patch14_384.safetensors", progress) + temp_path = os.path.join(INPUT_DIR, f"temp_style_{i}_{random.randint(1000, 9999)}.png") + st_images[i].save(temp_path, "PNG") + temp_files_to_clean.append(temp_path) + active_styles.append({ + "image": os.path.basename(temp_path), "strength": st_strengths[i] + }) + + reference_latent_data = ui_inputs.get('reference_latent_data', []) + active_reference_latents = [] + if reference_latent_data: + for img in reference_latent_data: + if img: + if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR) + temp_path = os.path.join(INPUT_DIR, f"temp_ref_{random.randint(1000, 9999)}.png") + img.save(temp_path, "PNG") + temp_files_to_clean.append(temp_path) + active_reference_latents.append(os.path.basename(temp_path)) + from utils.app_utils import get_vae_path vae_source = ui_inputs.get('vae_source') vae_id = ui_inputs.get('vae_id') - vae_file = ui_inputs.get('vae_file') vae_name_override = None - if vae_source and vae_source != "None": if vae_source == "File": vae_name_override = sanitize_filename(vae_id) elif vae_source == "Civitai" and vae_id and vae_id.strip(): - local_path, status = get_vae_path(vae_source, vae_id, ui_inputs.get('civitai_api_key'), progress) + local_path, status = get_vae_path(vae_source, vae_id, os.environ.get("CIVITAI_API_KEY", ""), progress) if local_path: vae_name_override = os.path.basename(local_path) else: raise gr.Error(f"Failed to prepare VAE {vae_id}: {status}") - if vae_name_override: ui_inputs['vae_name'] = vae_name_override @@ -276,78 +435,84 @@ class SdImagePipeline(BasePipeline): active_conditioning = [] if conditioning_data: num_units = len(conditioning_data) // 6 - prompts = conditioning_data[0*num_units : 1*num_units] - widths = conditioning_data[1*num_units : 2*num_units] - heights = conditioning_data[2*num_units : 3*num_units] - xs = conditioning_data[3*num_units : 4*num_units] - ys = conditioning_data[4*num_units : 5*num_units] - strengths = conditioning_data[5*num_units : 6*num_units] - + prompts, widths, heights, xs, ys, strengths = [conditioning_data[i*num_units : (i+1)*num_units] for i in range(6)] for i in range(num_units): if prompts[i] and prompts[i].strip(): active_conditioning.append({ - "prompt": prompts[i], - "width": int(widths[i]), - "height": int(heights[i]), - "x": int(xs[i]), - "y": int(ys[i]), - "strength": float(strengths[i]) + "prompt": prompts[i], "width": int(widths[i]), "height": int(heights[i]), + "x": int(xs[i]), "y": int(ys[i]), "strength": float(strengths[i]) }) - reference_latent_data = ui_inputs.get('reference_latent_data', []) - active_reference_latents = [] - if reference_latent_data: - for img_pil in reference_latent_data: - if img_pil is not None: - temp_file_path = os.path.join(INPUT_DIR, f"temp_ref_{random.randint(1000, 9999)}.png") - img_pil.save(temp_file_path, "PNG") - active_reference_latents.append(os.path.basename(temp_file_path)) - temp_files_to_clean.append(temp_file_path) - loras_string = f"LoRAs: [{', '.join(active_loras_for_meta)}]" if active_loras_for_meta else "" progress(0.8, desc="Assembling workflow...") if ui_inputs.get('seed') == -1: ui_inputs['seed'] = random.randint(0, 2**32 - 1) + + model_info = ALL_MODEL_MAP[model_display_name] + path_or_components = model_info[1] + latent_type = model_info[3] if len(model_info) > 3 and model_info[3] else 'latent' + latent_generator_template = "EmptyLatentImage" + if latent_type == 'sd3_latent': + latent_generator_template = "EmptySD3LatentImage" + elif latent_type == 'chroma_radiance_latent': + latent_generator_template = "EmptyChromaRadianceLatentImage" + elif latent_type == 'hunyuan_latent': + latent_generator_template = "EmptyHunyuanImageLatent" - dynamic_values = {'task_type': ui_inputs['task_type']} + dynamic_values = { + 'task_type': ui_inputs['task_type'], + 'model_type': workflow_model_type, + 'latent_type': latent_type, + 'latent_generator_template': latent_generator_template + } recipe_path = os.path.join(os.path.dirname(__file__), "workflow_recipes", "sd_unified_recipe.yaml") assembler = WorkflowAssembler(recipe_path, dynamic_values=dynamic_values) - model_display_name = ui_inputs['model_display_name'] - if model_display_name not in ALL_MODEL_MAP: - raise gr.Error(f"Model '{model_display_name}' is not configured in model_list.yaml.") - - _, components, _, _ = ALL_MODEL_MAP[model_display_name] - workflow_inputs = { + **ui_inputs, "positive_prompt": ui_inputs['positive_prompt'], "negative_prompt": ui_inputs['negative_prompt'], "seed": ui_inputs['seed'], "steps": ui_inputs['num_inference_steps'], "cfg": ui_inputs['guidance_scale'], "sampler_name": ui_inputs['sampler'], "scheduler": ui_inputs['scheduler'], "batch_size": ui_inputs['batch_size'], - "denoise": ui_inputs['denoise'], - "input_image": ui_inputs.get('input_image'), - "inpaint_image": ui_inputs.get('inpaint_image'), - "inpaint_mask": ui_inputs.get('inpaint_mask'), - "left": ui_inputs.get('outpaint_left'), "top": ui_inputs.get('outpaint_top'), - "right": ui_inputs.get('outpaint_right'), "bottom": ui_inputs.get('outpaint_bottom'), - "hires_upscaler": ui_inputs.get('hires_upscaler'), "hires_scale_by": ui_inputs.get('hires_scale_by'), - "unet_name": components['unet'], - "clip_name": components['clip'], - "vae_name": ui_inputs.get('vae_name', components['vae']), + "clip_skip": ui_inputs['clip_skip'], + "denoise": ui_inputs['denoise'], + "vae_name": ui_inputs.get('vae_name'), + "guidance": ui_inputs.get('guidance', 3.5), "lora_chain": active_loras_for_gpu, + "controlnet_chain": active_controlnets, + "diffsynth_controlnet_chain": active_diffsynth_controlnets, + "ipadapter_chain": active_ipadapters, + "flux1_ipadapter_chain": active_flux1_ipadapters, + "sd3_ipadapter_chain": active_sd3_ipadapters, + "style_chain": active_styles, "conditioning_chain": active_conditioning, "reference_latent_chain": active_reference_latents, + "vae_chain": [ui_inputs.get('vae_name')] if ui_inputs.get('vae_name') else [], } + + if isinstance(path_or_components, dict): + workflow_inputs.update({ + 'unet_name': path_or_components.get('unet'), + 'vae_name': ui_inputs.get('vae_name') or path_or_components.get('vae'), + 'clip_name': path_or_components.get('clip'), + 'clip1_name': path_or_components.get('clip1'), + 'clip2_name': path_or_components.get('clip2'), + 'clip3_name': path_or_components.get('clip3'), + 'clip4_name': path_or_components.get('clip4'), + 'lora_name': path_or_components.get('lora'), + }) + else: + workflow_inputs['model_name'] = path_or_components if task_type == 'txt2img': workflow_inputs['width'] = ui_inputs['width'] workflow_inputs['height'] = ui_inputs['height'] workflow = assembler.assemble(workflow_inputs) - + progress(1.0, desc="All models ready. Requesting GPU for generation...") try: @@ -362,7 +527,7 @@ class SdImagePipeline(BasePipeline): assembler=assembler, progress=progress ) - + import json import glob from PIL import PngImagePlugin diff --git a/core/pipelines/workflow_recipes/_partials/_base_sampler.yaml b/core/pipelines/workflow_recipes/_partials/_base_sampler.yaml deleted file mode 100644 index 63915d18a9406e57ab8db30538c81e1c47c6254e..0000000000000000000000000000000000000000 --- a/core/pipelines/workflow_recipes/_partials/_base_sampler.yaml +++ /dev/null @@ -1,23 +0,0 @@ -nodes: - ksampler: - class_type: KSampler - - vae_decode: - class_type: VAEDecode - save_image: - class_type: SaveImage - params: {} - -connections: - - from: "ksampler:0" - to: "vae_decode:samples" - - from: "vae_decode:0" - to: "save_image:images" - -ui_map: - seed: "ksampler:seed" - steps: "ksampler:steps" - cfg: "ksampler:cfg" - sampler_name: "ksampler:sampler_name" - scheduler: "ksampler:scheduler" - denoise: "ksampler:denoise" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/_base_sampler_sd.yaml b/core/pipelines/workflow_recipes/_partials/_base_sampler_sd.yaml new file mode 100644 index 0000000000000000000000000000000000000000..64780e0f91c03c4e26d2c48381ef2aef6453dd2a --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/_base_sampler_sd.yaml @@ -0,0 +1,36 @@ +nodes: + pos_prompt: + class_type: CLIPTextEncode + title: "CLIP Text Encode (Positive)" + neg_prompt: + class_type: CLIPTextEncode + title: "CLIP Text Encode (Negative)" + ksampler: + class_type: KSampler + title: "KSampler" + params: + denoise: 1.0 + vae_decode: + class_type: VAEDecode + title: "VAE Decode" + save_image: + class_type: SaveImage + title: "Save Image" + params: {} + +connections: + - from: "ksampler:0" + to: "vae_decode:samples" + - from: "vae_decode:0" + to: "save_image:images" + +ui_map: + positive_prompt: "pos_prompt:text" + negative_prompt: "neg_prompt:text" + seed: "ksampler:seed" + steps: "ksampler:steps" + cfg: "ksampler:cfg" + sampler_name: "ksampler:sampler_name" + scheduler: "ksampler:scheduler" + denoise: "ksampler:denoise" + filename_prefix: "save_image:filename_prefix" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/anima.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/anima.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f6a08f0afd20f53fe3c55680606b1ee1a0ef81e5 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/anima.yaml @@ -0,0 +1,54 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "stable_diffusion" + device: "default" + +connections: + - from: "unet_loader:0" + to: "ksampler:model" + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/chroma1-radiance.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/chroma1-radiance.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0b9a569f276b6ac2a909f9b06ee90e0f97eadf9a --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/chroma1-radiance.yaml @@ -0,0 +1,59 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + params: + vae_name: "pixel_space" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "chroma" + device: "default" + t5_tokenizer: + class_type: T5TokenizerOptions + title: "T5TokenizerOptions" + params: + min_padding: 0 + min_length: 3 + model_sampler: + class_type: ModelSamplingAuraFlow + params: + shift: 3.0 + +connections: + - from: "unet_loader:0" + to: "model_sampler:model" + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "t5_tokenizer:clip" + - from: "t5_tokenizer:0" + to: "pos_prompt:clip" + - from: "t5_tokenizer:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "t5_tokenizer:0" + +ui_map: + unet_name: "unet_loader:unet_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/chroma1.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/chroma1.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36430aab40403c6f865c0a8269ee71d96b995efe --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/chroma1.yaml @@ -0,0 +1,61 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "chroma" + device: "default" + t5_tokenizer: + class_type: T5TokenizerOptions + title: "T5TokenizerOptions" + params: + min_padding: 1 + min_length: 0 + fresca: + class_type: FreSca + title: "FreSca" + params: + scale_low: 1.0 + scale_high: 2.5 + freq_cutoff: 30 + +connections: + - from: "unet_loader:0" + to: "fresca:model" + - from: "fresca:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "t5_tokenizer:clip" + - from: "t5_tokenizer:0" + to: "pos_prompt:clip" + - from: "t5_tokenizer:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "t5_tokenizer:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/ernie-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/ernie-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..697ea92e2353f2ece2ebbbd5ca83230c54e87881 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/ernie-image.yaml @@ -0,0 +1,54 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "flux2" + device: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + +connections: + - from: "unet_loader:0" + to: "ksampler:model" + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + clip_name: "clip_loader:clip_name" + vae_name: "vae_loader:vae_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/flux1.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/flux1.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7fd114dd312caa0479598def74f6f57a0bedf564 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/flux1.yaml @@ -0,0 +1,64 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load FLUX UNET" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load FLUX VAE" + clip_loader: + class_type: DualCLIPLoader + title: "Load FLUX Dual CLIP" + params: + type: "flux" + device: "default" + flux_guidance: + class_type: FluxGuidance + title: "FluxGuidance" + +connections: + - from: "unet_loader:0" + to: "ksampler:model" + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + - from: "pos_prompt:0" + to: "flux_guidance:conditioning" + - from: "flux_guidance:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + +dynamic_controlnet_chains: + controlnet_chain: + template: "ControlNetApplyAdvanced" + ksampler_node: "ksampler" + vae_source: "vae_loader:0" + +dynamic_flux1_ipadapter_chains: + flux1_ipadapter_chain: + ksampler_node: "ksampler" + +dynamic_style_chains: + style_chain: + flux_guidance_node: "flux_guidance" + ksampler_node: "ksampler" + +dynamic_conditioning_chains: + conditioning_chain: + flux_guidance_node: "flux_guidance" + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip1_name: "clip_loader:clip_name1" + clip2_name: "clip_loader:clip_name2" + guidance: "flux_guidance:guidance" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/flux2-kv.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/flux2-kv.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c9cd6286f058a37e801c701e5d463228d66feadc --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/flux2-kv.yaml @@ -0,0 +1,104 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "flux2" + device: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + + flux_kv_cache: + class_type: FluxKVCache + title: "Flux KV Cache" + + pos_prompt: + class_type: CLIPTextEncode + title: "CLIP Text Encode (Positive)" + neg_prompt: + class_type: CLIPTextEncode + title: "CLIP Text Encode (Negative)" + + ksampler: + class_type: KSampler + title: "KSampler" + params: + denoise: 1.0 + + vae_decode: + class_type: VAEDecode + title: "VAE Decode" + + save_image: + class_type: SaveImage + title: "Save Image" + +connections: + - from: "unet_loader:0" + to: "flux_kv_cache:model" + - from: "flux_kv_cache:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "latent_source:0" + to: "ksampler:latent_image" + + - from: "ksampler:0" + to: "vae_decode:samples" + - from: "vae_decode:0" + to: "save_image:images" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["flux_kv_cache:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_reference_latent_chains: + reference_latent_chain: + ksampler_node: "ksampler" + vae_node: "vae_loader" + +ui_map: + unet_name: "unet_loader:unet_name" + clip_name: "clip_loader:clip_name" + vae_name: "vae_loader:vae_name" + + positive_prompt: "pos_prompt:text" + negative_prompt: "neg_prompt:text" + + seed: "ksampler:seed" + steps: "ksampler:steps" + cfg: "ksampler:cfg" + sampler_name: "ksampler:sampler_name" + scheduler: "ksampler:scheduler" + denoise: "ksampler:denoise" + + filename_prefix: "save_image:filename_prefix" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/flux2.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/flux2.yaml index 70ef1c15b20dc931b7f293aefa319f4662e4d68e..49a5c55bfceaf5b792939342d12da365185111e5 100644 --- a/core/pipelines/workflow_recipes/_partials/conditioning/flux2.yaml +++ b/core/pipelines/workflow_recipes/_partials/conditioning/flux2.yaml @@ -20,6 +20,20 @@ nodes: neg_prompt: class_type: CLIPTextEncode title: "CLIP Text Encode (Negative)" + + ksampler: + class_type: KSampler + title: "KSampler" + params: + denoise: 1.0 + + vae_decode: + class_type: VAEDecode + title: "VAE Decode" + + save_image: + class_type: SaveImage + title: "Save Image" connections: - from: "unet_loader:0" @@ -37,6 +51,14 @@ connections: to: "ksampler:positive" - from: "neg_prompt:0" to: "ksampler:negative" + + - from: "latent_source:0" + to: "ksampler:latent_image" + + - from: "ksampler:0" + to: "vae_decode:samples" + - from: "vae_decode:0" + to: "save_image:images" dynamic_lora_chains: lora_chain: @@ -51,11 +73,6 @@ dynamic_lora_chains: "model": ["ksampler:model"] "clip": ["pos_prompt:clip", "neg_prompt:clip"] -dynamic_conditioning_chains: - conditioning_chain: - ksampler_node: "ksampler" - clip_source: "clip_loader:0" - dynamic_reference_latent_chains: reference_latent_chain: ksampler_node: "ksampler" @@ -65,5 +82,15 @@ ui_map: unet_name: "unet_loader:unet_name" clip_name: "clip_loader:clip_name" vae_name: "vae_loader:vae_name" + positive_prompt: "pos_prompt:text" - negative_prompt: "neg_prompt:text" \ No newline at end of file + negative_prompt: "neg_prompt:text" + + seed: "ksampler:seed" + steps: "ksampler:steps" + cfg: "ksampler:cfg" + sampler_name: "ksampler:sampler_name" + scheduler: "ksampler:scheduler" + denoise: "ksampler:denoise" + + filename_prefix: "save_image:filename_prefix" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/hidream.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/hidream.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1163c69deabaf68762e0aee9e1c27b12014e3f89 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/hidream.yaml @@ -0,0 +1,53 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load HiDream UNET" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load HiDream VAE" + clip_loader: + class_type: QuadrupleCLIPLoader + title: "Load HiDream Quadruple CLIP" + + model_sampler: + class_type: ModelSamplingSD3 + title: "ModelSamplingSD3" + params: + shift: 6.0 + +connections: + - from: "unet_loader:0" + to: "model_sampler:model" + + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip1_name: "clip_loader:clip_name1" + clip2_name: "clip_loader:clip_name2" + clip3_name: "clip_loader:clip_name3" + clip4_name: "clip_loader:clip_name4" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/hunyuanimage.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/hunyuanimage.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7fa9a42af9a6be0ff527e532026bd33309fc9373 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/hunyuanimage.yaml @@ -0,0 +1,42 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Hunyuan UNET" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load Hunyuan VAE" + clip_loader: + class_type: DualCLIPLoader + title: "Load Hunyuan Dual CLIP" + params: + type: "hunyuan_image" + device: "default" + +connections: + - from: "unet_loader:0" + to: "ksampler:model" + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip1_name: "clip_loader:clip_name1" + clip2_name: "clip_loader:clip_name2" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/longcat-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/longcat-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..35097965ea3e30ae70c2d36019a8aa02e7709f9a --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/longcat-image.yaml @@ -0,0 +1,83 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "longcat_image" + device: "default" + + cfg_norm: + class_type: CFGNorm + title: "CFGNorm" + params: + strength: 1.0 + + flux_guidance_pos: + class_type: FluxGuidance + title: "FluxGuidance (Positive)" + params: + guidance: 4.0 + + flux_guidance_neg: + class_type: FluxGuidance + title: "FluxGuidance (Negative)" + params: + guidance: 4.0 + +connections: + - from: "unet_loader:0" + to: "cfg_norm:model" + - from: "cfg_norm:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "flux_guidance_pos:conditioning" + - from: "neg_prompt:0" + to: "flux_guidance_neg:conditioning" + + - from: "flux_guidance_pos:0" + to: "ksampler:positive" + - from: "flux_guidance_neg:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["cfg_norm:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + flux_guidance_node: "flux_guidance_pos" + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/lumina.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/lumina.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2559cd59370be528cfd28ccd5296d427b553d2ca --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/lumina.yaml @@ -0,0 +1,57 @@ +nodes: + ckpt_loader: + class_type: CheckpointLoaderSimple + title: "Load Checkpoint" + model_sampler: + class_type: ModelSamplingAuraFlow + title: "ModelSamplingAuraFlow" + params: + shift: 4.0 + +connections: + - from: "ckpt_loader:0" + to: "model_sampler:model" + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "ckpt_loader:1" + to: "pos_prompt:clip" + - from: "ckpt_loader:1" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "ckpt_loader:2" + to: "vae_decode:vae" + - from: "ckpt_loader:2" + to: "vae_encode:vae" + +dynamic_vae_chains: + vae_chain: + targets: + - "vae_decode:vae" + - "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + start: "ckpt_loader" + output_map: + "0": "model" + "1": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["model_sampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "ckpt_loader:1" + +ui_map: + model_name: "ckpt_loader:ckpt_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/newbie-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/newbie-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ab287fbd9977623f60c5d44977c8865ee61745c9 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/newbie-image.yaml @@ -0,0 +1,65 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: DualCLIPLoader + title: "Load Dual CLIP" + params: + type: "newbie" + device: "default" + model_sampler: + class_type: ModelSamplingAuraFlow + title: "ModelSamplingAuraFlow" + params: + shift: 6 + +connections: + - from: "unet_loader:0" + to: "model_sampler:model" + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_newbie_lora_chains: + lora_chain: + template: "NewBieLoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["model_sampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip1_name: "clip_loader:clip_name1" + clip2_name: "clip_loader:clip_name2" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/omnigen2.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/omnigen2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..81d9307dd57d41c4cf74c46e05df4d105a5689ba --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/omnigen2.yaml @@ -0,0 +1,59 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "omnigen2" + device: "default" + +connections: + - from: "unet_loader:0" + to: "ksampler:model" + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +dynamic_reference_latent_chains: + reference_latent_chain: + ksampler_node: "ksampler" + vae_node: "vae_loader" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/ovis-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/ovis-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ff757883324afc4fb2ec401bda3ae7f1bc0276d7 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/ovis-image.yaml @@ -0,0 +1,50 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "ovis" + device: "default" + model_sampler: + class_type: ModelSamplingAuraFlow + params: + shift: 3.0 + +connections: + - from: "unet_loader:0" + to: "model_sampler:model" + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/qwen-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/qwen-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9a8aa866a4a045fdf07841a4e229cc64cb254a04 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/qwen-image.yaml @@ -0,0 +1,80 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Qwen UNET" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load Qwen VAE" + clip_loader: + class_type: CLIPLoader + title: "Load Qwen CLIP" + params: + type: "qwen_image" + device: "default" + + lora_loader: + class_type: LoraLoaderModelOnly + title: "Load Qwen Lightning LoRA" + params: + strength_model: 1.0 + model_sampler: + class_type: ModelSamplingAuraFlow + title: "ModelSamplingAuraFlow" + params: + shift: 3.1 + +connections: + - from: "unet_loader:0" + to: "lora_loader:model" + - from: "lora_loader:0" + to: "model_sampler:model" + + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "lora_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["model_sampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_controlnet_chains: + controlnet_chain: + template: "ControlNetApplyAdvanced" + ksampler_node: "ksampler" + vae_source: "vae_loader:0" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" + lora_name: "lora_loader:lora_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/sd15.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/sd15.yaml new file mode 100644 index 0000000000000000000000000000000000000000..03858047f4a66d9a6fc83ab5b9c835b3580e199c --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/sd15.yaml @@ -0,0 +1,69 @@ +nodes: + ckpt_loader: + class_type: CheckpointLoaderSimple + title: "Load Checkpoint" + clip_set_last_layer: + class_type: CLIPSetLastLayer + title: "CLIP Set Last Layer" + +connections: + - from: "ckpt_loader:0" + to: "ksampler:model" + - from: "ckpt_loader:1" + to: "clip_set_last_layer:clip" + - from: "clip_set_last_layer:0" + to: "pos_prompt:clip" + - from: "clip_set_last_layer:0" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + - from: "ckpt_loader:2" + to: "vae_decode:vae" + - from: "ckpt_loader:2" + to: "vae_encode:vae" + +dynamic_vae_chains: + vae_chain: + targets: + - "vae_decode:vae" + - "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + start: "clip_set_last_layer" + output_map: + "ckpt_loader:0": "model" + "0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_controlnet_chains: + controlnet_chain: + template: "ControlNetApplyAdvanced" + ksampler_node: "ksampler" + vae_source: "ckpt_loader:2" + +dynamic_ipadapter_chains: + ipadapter_chain: + end: "ksampler" + final_preset: "{{ ipadapter_final_preset }}" + final_weight: "{{ ipadapter_final_weight }}" + final_embeds_scaling: "{{ ipadapter_embeds_scaling }}" + final_loader_type: "{{ ipadapter_final_loader_type }}" + final_lora_strength: "{{ ipadapter_final_lora_strength }}" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "clip_set_last_layer:0" + +ui_map: + model_name: "ckpt_loader:ckpt_name" + clip_skip: "clip_set_last_layer:stop_at_clip_layer" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/sd35.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/sd35.yaml new file mode 100644 index 0000000000000000000000000000000000000000..85429a678bfb8d2c44e222b513a348422c08f6f4 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/sd35.yaml @@ -0,0 +1,58 @@ +nodes: + ckpt_loader: + class_type: CheckpointLoaderSimple + title: "Load Checkpoint" + +connections: + - from: "ckpt_loader:0" + to: "ksampler:model" + - from: "ckpt_loader:1" + to: "pos_prompt:clip" + - from: "ckpt_loader:1" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + - from: "ckpt_loader:2" + to: "vae_decode:vae" + - from: "ckpt_loader:2" + to: "vae_encode:vae" + +dynamic_vae_chains: + vae_chain: + targets: + - "vae_decode:vae" + - "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + start: "ckpt_loader" + output_map: + "0": "model" + "1": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_controlnet_chains: + controlnet_chain: + template: "ControlNetApplyAdvanced" + ksampler_node: "ksampler" + vae_source: "ckpt_loader:2" + +dynamic_sd3_ipadapter_chains: + sd3_ipadapter_chain: + ksampler_node: "ksampler" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "ckpt_loader:1" + +ui_map: + model_name: "ckpt_loader:ckpt_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/sdxl.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/sdxl.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c4451f3fc935d3c3225c01938d2f655a561b6ea7 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/sdxl.yaml @@ -0,0 +1,63 @@ +nodes: + ckpt_loader: + class_type: CheckpointLoaderSimple + title: "Load Checkpoint" + +connections: + - from: "ckpt_loader:0" + to: "ksampler:model" + - from: "ckpt_loader:1" + to: "pos_prompt:clip" + - from: "ckpt_loader:1" + to: "neg_prompt:clip" + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + - from: "ckpt_loader:2" + to: "vae_decode:vae" + - from: "ckpt_loader:2" + to: "vae_encode:vae" + +dynamic_vae_chains: + vae_chain: + targets: + - "vae_decode:vae" + - "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + start: "ckpt_loader" + output_map: + "0": "model" + "1": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["ksampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_controlnet_chains: + controlnet_chain: + template: "ControlNetApplyAdvanced" + ksampler_node: "ksampler" + vae_source: "ckpt_loader:2" + +dynamic_ipadapter_chains: + ipadapter_chain: + end: "ksampler" + final_preset: "{{ ipadapter_final_preset }}" + final_weight: "{{ ipadapter_final_weight }}" + final_embeds_scaling: "{{ ipadapter_embeds_scaling }}" + final_loader_type: "{{ ipadapter_final_loader_type }}" + final_lora_strength: "{{ ipadapter_final_lora_strength }}" + +dynamic_conditioning_chains: + conditioning_chain: + ksampler_node: "ksampler" + clip_source: "ckpt_loader:1" + +ui_map: + model_name: "ckpt_loader:ckpt_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/conditioning/z-image.yaml b/core/pipelines/workflow_recipes/_partials/conditioning/z-image.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ad004372e475f5e6b33699b18c8f68ed1d8e28d7 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/conditioning/z-image.yaml @@ -0,0 +1,65 @@ +nodes: + unet_loader: + class_type: UNETLoader + title: "Load Diffusion Model" + params: + weight_dtype: "default" + vae_loader: + class_type: VAELoader + title: "Load VAE" + clip_loader: + class_type: CLIPLoader + title: "Load CLIP" + params: + type: "lumina2" + device: "default" + model_sampler: + class_type: ModelSamplingAuraFlow + params: + shift: 3.0 + +connections: + - from: "unet_loader:0" + to: "model_sampler:model" + - from: "model_sampler:0" + to: "ksampler:model" + + - from: "clip_loader:0" + to: "pos_prompt:clip" + - from: "clip_loader:0" + to: "neg_prompt:clip" + + - from: "pos_prompt:0" + to: "ksampler:positive" + - from: "neg_prompt:0" + to: "ksampler:negative" + + - from: "vae_loader:0" + to: "vae_decode:vae" + - from: "vae_loader:0" + to: "vae_encode:vae" + +dynamic_lora_chains: + lora_chain: + template: "LoraLoader" + output_map: + "unet_loader:0": "model" + "clip_loader:0": "clip" + input_map: + "model": "model" + "clip": "clip" + end_input_map: + "model": ["model_sampler:model"] + "clip": ["pos_prompt:clip", "neg_prompt:clip"] + +dynamic_diffsynth_controlnet_chains: + diffsynth_controlnet_chain: + template: "QwenImageDiffsynthControlnet" + model_sampler_node: "model_sampler" + ksampler_node: "ksampler" + vae_source: "vae_loader:0" + +ui_map: + unet_name: "unet_loader:unet_name" + vae_name: "vae_loader:vae_name" + clip_name: "clip_loader:clip_name" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/hires_fix.yaml b/core/pipelines/workflow_recipes/_partials/input/hires_fix.yaml index 6a0d7d4a911ac56c46257f40e05f100dcc8ffcc4..e9d3dc9ebe7edbad54a4b017a903adcbc4ec8dab 100644 --- a/core/pipelines/workflow_recipes/_partials/input/hires_fix.yaml +++ b/core/pipelines/workflow_recipes/_partials/input/hires_fix.yaml @@ -1,15 +1,16 @@ nodes: input_image_loader: class_type: LoadImage - + title: "Load Input Image" vae_encode: class_type: VAEEncode - + title: "VAE Encode (Hires Pre-step)" latent_upscaler: class_type: LatentUpscaleBy - + title: "Upscale Latent By" latent_source: class_type: RepeatLatentBatch + title: "Repeat Latent Batch for Hires" connections: - from: "input_image_loader:0" diff --git a/core/pipelines/workflow_recipes/_partials/input/img2img.yaml b/core/pipelines/workflow_recipes/_partials/input/img2img.yaml index 801d852c3450309dc078bc191b81e7fb5de4b88d..b753f53f77ed6971b995e7a5e3695b2b0ae12755 100644 --- a/core/pipelines/workflow_recipes/_partials/input/img2img.yaml +++ b/core/pipelines/workflow_recipes/_partials/input/img2img.yaml @@ -1,12 +1,13 @@ nodes: input_image_loader: class_type: LoadImage - + title: "Load Input Image" vae_encode: class_type: VAEEncode - + title: "VAE Encode (Img2Img)" latent_source: class_type: RepeatLatentBatch + title: "Repeat Latent Batch" connections: - from: "input_image_loader:0" diff --git a/core/pipelines/workflow_recipes/_partials/input/inpaint.yaml b/core/pipelines/workflow_recipes/_partials/input/inpaint.yaml index 24ef9e3a56b908cfabc5a71a28c7962cbaae43cd..93c9d37d8eef6029e077b54d2ecf264e17b69385 100644 --- a/core/pipelines/workflow_recipes/_partials/input/inpaint.yaml +++ b/core/pipelines/workflow_recipes/_partials/input/inpaint.yaml @@ -2,24 +2,22 @@ nodes: inpaint_loader: class_type: LoadImage title: "Load Inpaint Image+Mask" - vae_encode: class_type: VAEEncodeForInpaint - params: - grow_mask_by: 6 - + title: "VAE Encode (for Inpainting)" latent_source: class_type: RepeatLatentBatch - + title: "Repeat Latent Batch" + connections: - from: "inpaint_loader:0" to: "vae_encode:pixels" - from: "inpaint_loader:1" to: "vae_encode:mask" - - from: "vae_encode:0" to: "latent_source:samples" ui_map: - inpaint_image: "inpaint_loader:image" - batch_size: "latent_source:amount" \ No newline at end of file + input_image: "inpaint_loader:image" + batch_size: "latent_source:amount" + grow_mask_by: "vae_encode:grow_mask_by" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/outpaint.yaml b/core/pipelines/workflow_recipes/_partials/input/outpaint.yaml index cc51384adcadcc00a2b4af6309679cc4f76ea9a6..dc0631ed514d2eba5536ece529266a47b725a5d0 100644 --- a/core/pipelines/workflow_recipes/_partials/input/outpaint.yaml +++ b/core/pipelines/workflow_recipes/_partials/input/outpaint.yaml @@ -1,38 +1,41 @@ nodes: input_image_loader: class_type: LoadImage - + title: "Load Image for Outpaint" + scale_image: + class_type: ImageScaleToTotalPixels + title: "Scale Image to Total Pixels" + params: + upscale_method: "nearest-exact" pad_image: class_type: ImagePadForOutpaint - params: - feathering: 10 - + title: "Pad Image for Outpainting" vae_encode: class_type: VAEEncodeForInpaint - params: - grow_mask_by: 6 - + title: "VAE Encode (for Inpainting)" latent_source: class_type: RepeatLatentBatch + title: "Repeat Latent Batch" connections: - from: "input_image_loader:0" + to: "scale_image:image" + - from: "scale_image:0" to: "pad_image:image" - - from: "pad_image:0" to: "vae_encode:pixels" - from: "pad_image:1" to: "vae_encode:mask" - - from: "vae_encode:0" to: "latent_source:samples" ui_map: input_image: "input_image_loader:image" - + megapixels: "scale_image:megapixels" left: "pad_image:left" top: "pad_image:top" right: "pad_image:right" bottom: "pad_image:bottom" - + feathering: "pad_image:feathering" + grow_mask_by: "vae_encode:grow_mask_by" batch_size: "latent_source:amount" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img.yaml index 17423b0efa34f71c394f4540e38a767565f58361..df5957ccbc518741945d22232a154fb298e215f0 100644 --- a/core/pipelines/workflow_recipes/_partials/input/txt2img.yaml +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img.yaml @@ -1,8 +1,2 @@ -nodes: - latent_source: - class_type: EmptyFlux2LatentImage - -ui_map: - width: "latent_source:width" - height: "latent_source:height" - batch_size: "latent_source:batch_size" \ No newline at end of file +imports: + - "txt2img_{{ latent_type }}.yaml" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img_chroma_radiance_latent.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img_chroma_radiance_latent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..afd3897cfe93f950edd9c7753813e5545b29acf5 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img_chroma_radiance_latent.yaml @@ -0,0 +1,11 @@ +nodes: + latent_source: + class_type: "EmptyChromaRadianceLatentImage" + title: "EmptyChromaRadianceLatentImage" + +connections: [] + +ui_map: + width: "latent_source:width" + height: "latent_source:height" + batch_size: "latent_source:batch_size" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img_flux2_latent.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img_flux2_latent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..95f1e8d5949cdf754ab158db1c04142cf0941c86 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img_flux2_latent.yaml @@ -0,0 +1,11 @@ +nodes: + latent_source: + class_type: "EmptyFlux2LatentImage" + title: "Empty Flux 2 Latent" + +connections: [] + +ui_map: + width: "latent_source:width" + height: "latent_source:height" + batch_size: "latent_source:batch_size" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img_hunyuan_latent.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img_hunyuan_latent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8e51ba57d67a8defaab28af552ed537d85e69eb7 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img_hunyuan_latent.yaml @@ -0,0 +1,11 @@ +nodes: + latent_source: + class_type: "EmptyHunyuanImageLatent" + title: "EmptyHunyuanImageLatent" + +connections: [] + +ui_map: + width: "latent_source:width" + height: "latent_source:height" + batch_size: "latent_source:batch_size" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img_latent.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img_latent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..660a34331c2dd17882ba3398ea4a4dedd822c6a7 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img_latent.yaml @@ -0,0 +1,11 @@ +nodes: + latent_source: + class_type: "{{ latent_generator_template }}" + title: "Empty Latent Image" + +connections: [] + +ui_map: + width: "latent_source:width" + height: "latent_source:height" + batch_size: "latent_source:batch_size" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/_partials/input/txt2img_sd3_latent.yaml b/core/pipelines/workflow_recipes/_partials/input/txt2img_sd3_latent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fc9d1f5e58b90ff14cb460de95b6ac653f641239 --- /dev/null +++ b/core/pipelines/workflow_recipes/_partials/input/txt2img_sd3_latent.yaml @@ -0,0 +1,11 @@ +nodes: + latent_source: + class_type: "EmptySD3LatentImage" + title: "EmptySD3LatentImage" + +connections: [] + +ui_map: + width: "latent_source:width" + height: "latent_source:height" + batch_size: "latent_source:batch_size" \ No newline at end of file diff --git a/core/pipelines/workflow_recipes/sd_unified_recipe.yaml b/core/pipelines/workflow_recipes/sd_unified_recipe.yaml index 024fa591cf73109d169f55782e77518498673735..49c2ea500e0e24d7faea454da913bd646e033a67 100644 --- a/core/pipelines/workflow_recipes/sd_unified_recipe.yaml +++ b/core/pipelines/workflow_recipes/sd_unified_recipe.yaml @@ -1,7 +1,7 @@ imports: - - "_partials/_base_sampler.yaml" + - "_partials/_base_sampler_sd.yaml" - "_partials/input/{{ task_type }}.yaml" - - "_partials/conditioning/flux2.yaml" + - "_partials/conditioning/{{ model_type }}.yaml" connections: - from: "latent_source:0" diff --git a/core/settings.py b/core/settings.py index 99a3a63cd5ba8dfa4d0f269c53e46e73f7219388..55cbd0ca3f161ace06b32aec1a69773870fbe8b6 100644 --- a/core/settings.py +++ b/core/settings.py @@ -10,16 +10,37 @@ MODEL_PATCHES_DIR = "models/model_patches" DIFFUSION_MODELS_DIR = "models/diffusion_models" VAE_DIR = "models/vae" TEXT_ENCODERS_DIR = "models/text_encoders" +STYLE_MODELS_DIR = "models/style_models" +CLIP_VISION_DIR = "models/clip_vision" +IPADAPTER_DIR = "models/ipadapter" +IPADAPTER_FLUX_DIR = "models/ipadapter-flux" INPUT_DIR = "input" OUTPUT_DIR = "output" +CATEGORY_TO_DIR_MAP = { + "diffusion_models": DIFFUSION_MODELS_DIR, + "text_encoders": TEXT_ENCODERS_DIR, + "vae": VAE_DIR, + "checkpoints": CHECKPOINT_DIR, + "loras": LORA_DIR, + "controlnet": CONTROLNET_DIR, + "model_patches": MODEL_PATCHES_DIR, + "embeddings": EMBEDDING_DIR, + "style_models": STYLE_MODELS_DIR, + "clip_vision": CLIP_VISION_DIR, + "ipadapter": IPADAPTER_DIR, + "ipadapter-flux": IPADAPTER_FLUX_DIR +} + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) _MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_list.yaml') _FILE_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'file_list.yaml') +_IPADAPTER_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml') _CONSTANTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'constants.yaml') +_MODEL_ARCHITECTURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_architectures.yaml') +_IMAGE_GEN_FEATURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'image_gen_features.yaml') _MODEL_DEFAULTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_defaults.yaml') - def load_constants_from_yaml(filepath=_CONSTANTS_PATH): if not os.path.exists(filepath): print(f"Warning: Constants file not found at {filepath}. Using fallback values.") @@ -27,6 +48,27 @@ def load_constants_from_yaml(filepath=_CONSTANTS_PATH): with open(filepath, 'r', encoding='utf-8') as f: return yaml.safe_load(f) +def load_architectures_config(filepath=_MODEL_ARCHITECTURES_PATH): + if not os.path.exists(filepath): + print(f"Warning: Architectures file not found at {filepath}.") + return {} + with open(filepath, 'r', encoding='utf-8') as f: + return yaml.safe_load(f) + +def load_features_config(filepath=_IMAGE_GEN_FEATURES_PATH): + if not os.path.exists(filepath): + print(f"Warning: Features file not found at {filepath}.") + return {} + with open(filepath, 'r', encoding='utf-8') as f: + return yaml.safe_load(f) + +def load_model_defaults(filepath=_MODEL_DEFAULTS_PATH): + if not os.path.exists(filepath): + print(f"Warning: Model defaults file not found at {filepath}.") + return {} + with open(filepath, 'r', encoding='utf-8') as f: + return yaml.safe_load(f) + def load_file_download_map(filepath=_FILE_LIST_PATH): if not os.path.exists(filepath): raise FileNotFoundError(f"The file list (for downloads) was not found at: {filepath}") @@ -59,50 +101,86 @@ def load_models_from_yaml(model_list_filepath=_MODEL_LIST_PATH, download_map=Non } category_map_names = { "Checkpoint": "MODEL_MAP_CHECKPOINT", + "Checkpoints": "MODEL_MAP_CHECKPOINT" } - for category, models in model_data.items(): + for category, architectures in model_data.items(): if category in category_map_names: map_name = category_map_names[category] - if not isinstance(models, list): continue - for model in models: - display_name = model['display_name'] - components = model.get('components', {}) - - model_tuple = ( - None, - components, - "SDXL", - None - ) - model_maps[map_name][display_name] = model_tuple - model_maps["ALL_MODEL_MAP"][display_name] = model_tuple + if not isinstance(architectures, dict): continue + + for arch, arch_data in architectures.items(): + if not isinstance(arch_data, dict): continue + + latent_type = arch_data.get('latent_type', 'latent') + models = arch_data.get('models', []) + if not isinstance(models, list): continue + + for model in models: + display_name = model['display_name'] + path_or_components = model.get('path') or model.get('components') + mod_category = model.get('category', None) + + repo_id = '' + if isinstance(path_or_components, str): + download_info = download_map.get(path_or_components, {}) + repo_id = download_info.get('repo_id', '') + + model_tuple = ( + repo_id, + path_or_components, + arch, + latent_type, + mod_category + ) + model_maps[map_name][display_name] = model_tuple + model_maps["ALL_MODEL_MAP"][display_name] = model_tuple return model_maps -def load_model_defaults(filepath=_MODEL_DEFAULTS_PATH): - if not os.path.exists(filepath): - print(f"Warning: Model defaults file not found at {filepath}. Using empty defaults.") - return {} - with open(filepath, 'r', encoding='utf-8') as f: - return yaml.safe_load(f) - try: ALL_FILE_DOWNLOAD_MAP = load_file_download_map() loaded_maps = load_models_from_yaml(download_map=ALL_FILE_DOWNLOAD_MAP) MODEL_MAP_CHECKPOINT = loaded_maps["MODEL_MAP_CHECKPOINT"] ALL_MODEL_MAP = loaded_maps["ALL_MODEL_MAP"] + category_to_model_type = { + "diffusion_models": "UNET", + "text_encoders": "TEXT_ENCODER", + "vae": "VAE", + "checkpoints": "SDXL", + "loras": "LORA", + "controlnet": "CONTROLNET", + "model_patches": "MODEL_PATCH", + "style_models": "STYLE", + "clip_vision": "CLIP_VISION", + "ipadapter": "IPADAPTER", + "ipadapter-flux": "IPADAPTER_FLUX" + } + for filename, file_info in ALL_FILE_DOWNLOAD_MAP.items(): + if filename not in ALL_MODEL_MAP: + category = file_info.get('category') + model_type = category_to_model_type.get(category, 'UNKNOWN') + repo_id = file_info.get('repo_id', '') + ALL_MODEL_MAP[filename] = (repo_id, filename, model_type, None, None) + MODEL_TYPE_MAP = {k: v[2] for k, v in ALL_MODEL_MAP.items()} - - ALL_MODEL_DEFAULTS = load_model_defaults() + + ARCH_CATEGORIES_MAP = {} + for display_name, info in MODEL_MAP_CHECKPOINT.items(): + arch = info[2] + cat = info[4] if len(info) > 4 else None + if arch not in ARCH_CATEGORIES_MAP: + ARCH_CATEGORIES_MAP[arch] = [] + if cat and cat not in ARCH_CATEGORIES_MAP[arch]: + ARCH_CATEGORIES_MAP[arch].append(cat) except Exception as e: print(f"FATAL: Could not load model configuration from YAML. Error: {e}") ALL_FILE_DOWNLOAD_MAP = {} MODEL_MAP_CHECKPOINT, ALL_MODEL_MAP = {}, {} MODEL_TYPE_MAP = {} - ALL_MODEL_DEFAULTS = {} + ARCH_CATEGORIES_MAP = {} try: @@ -111,15 +189,17 @@ try: MAX_EMBEDDINGS = _constants.get('MAX_EMBEDDINGS', 5) MAX_CONDITIONINGS = _constants.get('MAX_CONDITIONINGS', 10) MAX_CONTROLNETS = _constants.get('MAX_CONTROLNETS', 5) - MAX_REFERENCE_LATENTS = _constants.get('MAX_REFERENCE_LATENTS', 10) + MAX_IPADAPTERS = _constants.get('MAX_IPADAPTERS', 5) LORA_SOURCE_CHOICES = _constants.get('LORA_SOURCE_CHOICES', ["Civitai", "File"]) RESOLUTION_MAP = _constants.get('RESOLUTION_MAP', {}) + ARCHITECTURES_CONFIG = load_architectures_config() + FEATURES_CONFIG = load_features_config() + MODEL_DEFAULTS_CONFIG = load_model_defaults() except Exception as e: print(f"FATAL: Could not load constants from YAML. Error: {e}") - MAX_LORAS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_CONTROLNETS = 5, 5, 10, 5 - MAX_REFERENCE_LATENTS = 10 + MAX_LORAS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_CONTROLNETS, MAX_IPADAPTERS = 5, 5, 10, 5, 5 LORA_SOURCE_CHOICES = ["Civitai", "File"] RESOLUTION_MAP = {} - - -DEFAULT_NEGATIVE_PROMPT = "" \ No newline at end of file + ARCHITECTURES_CONFIG = {} + FEATURES_CONFIG = {} + MODEL_DEFAULTS_CONFIG = {} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index dd463cd02b9f69107d470a508751eab6950ecdf3..09c8420bf7f94f6d8dadbdf95ffbe4608f2636f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -comfyui-frontend-package==1.42.14 -comfyui-workflow-templates==0.9.59 -comfyui-embedded-docs==0.4.3 +comfyui-frontend-package==1.42.15 +comfyui-workflow-templates==0.9.66 +comfyui-embedded-docs==0.4.4 torch==2.10.0 torchsde torchvision==0.25.0 @@ -19,11 +19,11 @@ scipy tqdm psutil alembic -SQLAlchemy>=2.0 +SQLAlchemy>=2.0.0 filelock av>=14.2.0 comfy-kitchen>=0.2.8 -comfy-aimdo>=0.2.12 +comfy-aimdo==0.3.0 requests simpleeval>=1.0.0 blake3 @@ -58,4 +58,5 @@ svglib trimesh[easy] yacs yapf -onnxruntime-gpu \ No newline at end of file +onnxruntime-gpu +diffusers \ No newline at end of file diff --git a/ui/events.py b/ui/events.py index 9a8a35449fa6985f893c80ed6104bac50abb2053..931923fb976e7beb4947ecd1efdae24962b0e5dd 100644 --- a/ui/events.py +++ b/ui/events.py @@ -8,150 +8,193 @@ from utils.app_utils import * from core.generation_logic import * from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES -from core.pipelines.controlnet_preprocessor import CPU_ONLY_PREPROCESSORS -from utils.app_utils import PREPROCESSOR_MODEL_MAP, PREPROCESSOR_PARAMETER_MAP, save_uploaded_file_with_hash -from ui.shared.ui_components import RESOLUTION_MAP, MAX_CONTROLNETS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_LORAS, MAX_REFERENCE_LATENTS +from utils.app_utils import save_uploaded_file_with_hash +from ui.shared.ui_components import RESOLUTION_MAP, MAX_CONTROLNETS, MAX_IPADAPTERS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_LORAS -def on_model_change(model_display_name): - """ - Callback function to update UI elements when the base model changes. - It loads default values for steps and cfg from model_defaults.yaml. - """ - defaults = ALL_MODEL_DEFAULTS.get('Default', {}).copy() +@lru_cache(maxsize=1) +def load_controlnet_config(): + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + _CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'controlnet_models.yaml') + try: + print("--- Loading controlnet_models.yaml ---") + with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + print("--- ✅ controlnet_models.yaml loaded successfully ---") + return config.get("ControlNet", {}) + except Exception as e: + print(f"Error loading controlnet_models.yaml: {e}") + return {} + + +def get_cn_defaults(arch_val): + cn_full_config = load_controlnet_config() + cn_config = cn_full_config.get(arch_val, []) - model_found = False - for category, models_in_category in ALL_MODEL_DEFAULTS.items(): - if category == 'Default' or not isinstance(models_in_category, dict): - continue - - if model_display_name in models_in_category: - if '_defaults' in models_in_category: - defaults.update(models_in_category['_defaults']) - defaults.update(models_in_category[model_display_name]) - model_found = True - break + if not cn_config: + return [], None, [], None, "None" + + all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", [])))) + default_type = all_types[0] if all_types else None - if not model_found: - print(f"No specific defaults found for '{model_display_name}'. Using category or global defaults.") + series_choices = [] + if default_type: + series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", [])))) + default_series = series_choices[0] if series_choices else None + + filepath = "None" + if default_series and default_type: + for model in cn_config: + if model.get("Series") == default_series and default_type in model.get("Type", []): + filepath = model.get("Filepath") + break + + return all_types, default_type, series_choices, default_series, filepath + +@lru_cache(maxsize=1) +def load_diffsynth_controlnet_config(): + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + _CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'diffsynth_controlnet_models.yaml') + try: + print("--- Loading diffsynth_controlnet_models.yaml ---") + with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + print("--- ✅ diffsynth_controlnet_models.yaml loaded successfully ---") + return config.get("DiffSynth_ControlNet", {}) + except Exception as e: + print(f"Error loading diffsynth_controlnet_models.yaml: {e}") + return {} - steps_update = gr.update(value=defaults.get('steps')) - cfg_update = gr.update(value=defaults.get('cfg')) +def get_diffsynth_cn_defaults(arch_val): + cn_full_config = load_diffsynth_controlnet_config() + cn_config = cn_full_config.get(arch_val, []) - return steps_update, cfg_update + if not cn_config: + return [], None, [], None, "None" + + all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", [])))) + default_type = all_types[0] if all_types else None + + series_choices = [] + if default_type: + series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", [])))) + default_series = series_choices[0] if series_choices else None + + filepath = "None" + if default_series and default_type: + for model in cn_config: + if model.get("Series") == default_series and default_type in model.get("Type", []): + filepath = model.get("Filepath") + break + + return all_types, default_type, series_choices, default_series, filepath -def attach_event_handlers(ui_components, demo): - def update_cn_input_visibility(choice): - return { - ui_components["cn_image_input"]: gr.update(visible=choice == "Image"), - ui_components["cn_video_input"]: gr.update(visible=choice == "Video") - } - ui_components["cn_input_type"].change( - fn=update_cn_input_visibility, - inputs=[ui_components["cn_input_type"]], - outputs=[ui_components["cn_image_input"], ui_components["cn_video_input"]] - ) + +@lru_cache(maxsize=1) +def load_ipadapter_config(): + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + _IPA_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml') + try: + print("--- Loading ipadapter.yaml ---") + with open(_IPA_MODEL_LIST_PATH, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + print("--- ✅ ipadapter.yaml loaded successfully ---") + return config + except Exception as e: + print(f"Error loading ipadapter.yaml: {e}") + return {} + + +def apply_data_to_ui(data, prefix, ui_components): + final_sampler = data.get('sampler') if data.get('sampler') in SAMPLER_CHOICES else SAMPLER_CHOICES[0] + default_scheduler = 'normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0] + final_scheduler = data.get('scheduler') if data.get('scheduler') in SCHEDULER_CHOICES else default_scheduler + + updates = {} + base_model_name = data.get('base_model') - def update_preprocessor_models_dropdown(preprocessor_name): - models = PREPROCESSOR_MODEL_MAP.get(preprocessor_name) - if models: - model_filenames = [m[1] for m in models] - return gr.update(choices=model_filenames, value=model_filenames[0], visible=True) - else: - return gr.update(choices=[], value=None, visible=False) - - def update_preprocessor_settings_ui(preprocessor_name): - from ui.layout import MAX_DYNAMIC_CONTROLS - params = PREPROCESSOR_PARAMETER_MAP.get(preprocessor_name, []) - - slider_updates, dropdown_updates, checkbox_updates = [], [], [] - - s_idx, d_idx, c_idx = 0, 0, 0 - - for param in params: - if s_idx + d_idx + c_idx >= MAX_DYNAMIC_CONTROLS: break - - name = param["name"] - ptype = param["type"] - config = param["config"] - label = name.replace('_', ' ').title() - - if ptype == "INT" or ptype == "FLOAT": - if s_idx < MAX_DYNAMIC_CONTROLS: - slider_updates.append(gr.update( - label=label, - minimum=config.get('min', 0), - maximum=config.get('max', 255), - step=config.get('step', 0.1 if ptype == "FLOAT" else 1), - value=config.get('default', 0), - visible=True - )) - s_idx += 1 - elif isinstance(ptype, list): - if d_idx < MAX_DYNAMIC_CONTROLS: - dropdown_updates.append(gr.update( - label=label, - choices=ptype, - value=config.get('default', ptype[0] if ptype else None), - visible=True - )) - d_idx += 1 - elif ptype == "BOOLEAN": - if c_idx < MAX_DYNAMIC_CONTROLS: - checkbox_updates.append(gr.update( - label=label, - value=config.get('default', False), - visible=True - )) - c_idx += 1 - - for _ in range(s_idx, MAX_DYNAMIC_CONTROLS): slider_updates.append(gr.update(visible=False)) - for _ in range(d_idx, MAX_DYNAMIC_CONTROLS): dropdown_updates.append(gr.update(visible=False)) - for _ in range(c_idx, MAX_DYNAMIC_CONTROLS): checkbox_updates.append(gr.update(visible=False)) - - return slider_updates + dropdown_updates + checkbox_updates - - def update_run_button_for_cpu(preprocessor_name): - if preprocessor_name in CPU_ONLY_PREPROCESSORS: - return gr.update(value="Run Preprocessor CPU Only", variant="primary"), gr.update(visible=False) + model_map = MODEL_MAP_CHECKPOINT + + if f'base_model_{prefix}' in ui_components: + model_dropdown_component = ui_components[f'base_model_{prefix}'] + if base_model_name and base_model_name in model_map: + updates[model_dropdown_component] = base_model_name + if f'model_arch_{prefix}' in ui_components: + m_type = MODEL_TYPE_MAP.get(base_model_name, "SDXL") + updates[ui_components[f'model_arch_{prefix}']] = m_type + if f'model_cat_{prefix}' in ui_components: + m_info = model_map.get(base_model_name) + m_cat = m_info[4] if m_info and len(m_info) > 4 else None + updates[ui_components[f'model_cat_{prefix}']] = m_cat if m_cat else "ALL" else: - return gr.update(value="Run Preprocessor", variant="primary"), gr.update(visible=True) - - ui_components["preprocessor_cn"].change( - fn=update_preprocessor_models_dropdown, - inputs=[ui_components["preprocessor_cn"]], - outputs=[ui_components["preprocessor_model_cn"]] - ).then( - fn=update_preprocessor_settings_ui, - inputs=[ui_components["preprocessor_cn"]], - outputs=ui_components["cn_sliders"] + ui_components["cn_dropdowns"] + ui_components["cn_checkboxes"] - ).then( - fn=update_run_button_for_cpu, - inputs=[ui_components["preprocessor_cn"]], - outputs=[ui_components["run_cn"], ui_components["zero_gpu_cn"]] - ) - - all_dynamic_inputs = ( - ui_components["cn_sliders"] + - ui_components["cn_dropdowns"] + - ui_components["cn_checkboxes"] - ) - - ui_components["run_cn"].click( - fn=run_cn_preprocessor_entry, - inputs=[ - ui_components["cn_input_type"], - ui_components["cn_image_input"], - ui_components["cn_video_input"], - ui_components["preprocessor_cn"], - ui_components["preprocessor_model_cn"], - ui_components["zero_gpu_cn"], - ] + all_dynamic_inputs, - outputs=[ui_components["output_gallery_cn"]] - ) + updates[model_dropdown_component] = gr.update() + + common_params = { + f'prompt_{prefix}': data.get('prompt', ''), + f'neg_prompt_{prefix}': data.get('negative_prompt', ''), + f'seed_{prefix}': data.get('seed', -1), + f'cfg_{prefix}': data.get('cfg_scale', 7.5), + f'steps_{prefix}': data.get('steps', 28), + f'sampler_{prefix}': final_sampler, + f'scheduler_{prefix}': final_scheduler, + } + + for comp_name, value in common_params.items(): + if comp_name in ui_components: + updates[ui_components[comp_name]] = value + + if prefix == 'txt2img': + if f'width_{prefix}' in ui_components: + updates[ui_components[f'width_{prefix}']] = data.get('width', 1024) + if f'height_{prefix}' in ui_components: + updates[ui_components[f'height_{prefix}']] = data.get('height', 1024) + + tab_indices = {"txt2img": 0, "img2img": 1, "inpaint": 2, "outpaint": 3, "hires_fix": 4} + tab_index = tab_indices.get(prefix, 0) + + updates[ui_components['tabs']] = gr.Tabs(selected=tab_index) + + return updates + + +def send_info_to_tab(image, prefix, ui_components): + if not image or not image.info.get('parameters', ''): + all_comps = [comp for comp_or_list in ui_components.values() for comp in (comp_or_list if isinstance(comp_or_list, list) else [comp_or_list])] + return {comp: gr.update() for comp in all_comps} + + data = parse_parameters(image.info['parameters']) + + image_input_map = { + "img2img": 'input_image_img2img', + "inpaint": 'input_image_dict_inpaint', + "outpaint": 'input_image_outpaint', + "hires_fix": 'input_image_hires_fix' + } + + updates = apply_data_to_ui(data, prefix, ui_components) + + if prefix in image_input_map and image_input_map[prefix] in ui_components: + component_key = image_input_map[prefix] + updates[ui_components[component_key]] = gr.update(value=image) + + return updates + +def send_info_by_hash(image, ui_components): + if not image or not image.info.get('parameters', ''): + all_comps = [comp for comp_or_list in ui_components.values() for comp in (comp_or_list if isinstance(comp_or_list, list) else [comp_or_list])] + return {comp: gr.update() for comp in all_comps} + + data = parse_parameters(image.info['parameters']) + + return apply_data_to_ui(data, "txt2img", ui_components) + + +def attach_event_handlers(ui_components, demo): + def create_lora_event_handlers(prefix): - lora_rows = ui_components[f'lora_rows_{prefix}'] + lora_rows = ui_components.get(f'lora_rows_{prefix}') + if not lora_rows: return lora_ids = ui_components[f'lora_ids_{prefix}'] lora_scales = ui_components[f'lora_scales_{prefix}'] lora_uploads = ui_components[f'lora_uploads_{prefix}'] @@ -190,8 +233,362 @@ def attach_event_handlers(ui_components, demo): add_button.click(add_lora_row, [count_state], add_outputs, show_progress=False) del_button.click(del_lora_row, [count_state], del_outputs, show_progress=False) + def create_controlnet_event_handlers(prefix): + cn_rows = ui_components.get(f'controlnet_rows_{prefix}') + if not cn_rows: return + cn_types = ui_components[f'controlnet_types_{prefix}'] + cn_series = ui_components[f'controlnet_series_{prefix}'] + cn_filepaths = ui_components[f'controlnet_filepaths_{prefix}'] + cn_images = ui_components[f'controlnet_images_{prefix}'] + cn_strengths = ui_components[f'controlnet_strengths_{prefix}'] + + count_state = ui_components[f'controlnet_count_state_{prefix}'] + add_button = ui_components[f'add_controlnet_button_{prefix}'] + del_button = ui_components[f'delete_controlnet_button_{prefix}'] + accordion = ui_components[f'controlnet_accordion_{prefix}'] + + arch_comp = ui_components.get(f'model_arch_{prefix}') + actual_arch_comp = arch_comp if arch_comp else gr.State("SDXL") + + def add_cn_row(c): + c += 1 + updates = { + count_state: c, + cn_rows[c-1]: gr.update(visible=True), + add_button: gr.update(visible=c < MAX_CONTROLNETS), + del_button: gr.update(visible=True) + } + return updates + + def del_cn_row(c): + c -= 1 + updates = { + count_state: c, + cn_rows[c]: gr.update(visible=False), + cn_images[c]: None, + cn_strengths[c]: 1.0, + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0) + } + return updates + + add_outputs = [count_state, add_button, del_button] + cn_rows + del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths + add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def on_cn_type_change(selected_type, arch_val): + cn_full_config = load_controlnet_config() + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + controlnet_key = architectures_dict.get(arch_val, {}).get("controlnet_key", arch_val) + + cn_config = cn_full_config.get(controlnet_key, []) + series_choices = [] + if selected_type: + series_choices = sorted(list(set( + model.get("Series", "Default") for model in cn_config + if selected_type in model.get("Type", []) + ))) + default_series = series_choices[0] if series_choices else None + filepath = "None" + if default_series: + for model in cn_config: + if model.get("Series") == default_series and selected_type in model.get("Type", []): + filepath = model.get("Filepath") + break + return gr.update(choices=series_choices, value=default_series), filepath + + def on_cn_series_change(selected_series, selected_type, arch_val): + cn_full_config = load_controlnet_config() + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + controlnet_key = architectures_dict.get(arch_val, {}).get("controlnet_key", arch_val) + + cn_config = cn_full_config.get(controlnet_key, []) + filepath = "None" + if selected_series and selected_type: + for model in cn_config: + if model.get("Series") == selected_series and selected_type in model.get("Type", []): + filepath = model.get("Filepath") + break + return filepath + + for i in range(MAX_CONTROLNETS): + cn_types[i].change( + fn=on_cn_type_change, + inputs=[cn_types[i], actual_arch_comp], + outputs=[cn_series[i], cn_filepaths[i]], + show_progress=False + ) + cn_series[i].change( + fn=on_cn_series_change, + inputs=[cn_series[i], cn_types[i], actual_arch_comp], + outputs=[cn_filepaths[i]], + show_progress=False + ) + + def on_accordion_expand(*images): + return [gr.update() for _ in images] + + accordion.expand( + fn=on_accordion_expand, + inputs=cn_images, + outputs=cn_images, + show_progress=False + ) + + def create_diffsynth_controlnet_event_handlers(prefix): + cn_rows = ui_components.get(f'diffsynth_controlnet_rows_{prefix}') + if not cn_rows: return + cn_types = ui_components[f'diffsynth_controlnet_types_{prefix}'] + cn_series = ui_components[f'diffsynth_controlnet_series_{prefix}'] + cn_filepaths = ui_components[f'diffsynth_controlnet_filepaths_{prefix}'] + cn_images = ui_components[f'diffsynth_controlnet_images_{prefix}'] + cn_strengths = ui_components[f'diffsynth_controlnet_strengths_{prefix}'] + + count_state = ui_components[f'diffsynth_controlnet_count_state_{prefix}'] + add_button = ui_components[f'add_diffsynth_controlnet_button_{prefix}'] + del_button = ui_components[f'delete_diffsynth_controlnet_button_{prefix}'] + accordion = ui_components[f'diffsynth_controlnet_accordion_{prefix}'] + + arch_comp = ui_components.get(f'model_arch_{prefix}') + actual_arch_comp = arch_comp if arch_comp else gr.State("Z-Image") + + def add_cn_row(c): + c += 1 + updates = { + count_state: c, + cn_rows[c-1]: gr.update(visible=True), + add_button: gr.update(visible=c < MAX_CONTROLNETS), + del_button: gr.update(visible=True) + } + return updates + + def del_cn_row(c): + c -= 1 + updates = { + count_state: c, + cn_rows[c]: gr.update(visible=False), + cn_images[c]: None, + cn_strengths[c]: 1.0, + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0) + } + return updates + + add_outputs = [count_state, add_button, del_button] + cn_rows + del_outputs = [count_state, add_button, del_button] + cn_rows + cn_images + cn_strengths + add_button.click(fn=add_cn_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_cn_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def on_cn_type_change(selected_type, arch_val): + cn_full_config = load_diffsynth_controlnet_config() + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + controlnet_key = architectures_dict.get(arch_val, {}).get("controlnet_key", arch_val) + + cn_config = cn_full_config.get(controlnet_key, []) + series_choices = [] + if selected_type: + series_choices = sorted(list(set( + model.get("Series", "Default") for model in cn_config + if selected_type in model.get("Type", []) + ))) + default_series = series_choices[0] if series_choices else None + filepath = "None" + if default_series: + for model in cn_config: + if model.get("Series") == default_series and selected_type in model.get("Type", []): + filepath = model.get("Filepath") + break + return gr.update(choices=series_choices, value=default_series), filepath + + def on_cn_series_change(selected_series, selected_type, arch_val): + cn_full_config = load_diffsynth_controlnet_config() + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + controlnet_key = architectures_dict.get(arch_val, {}).get("controlnet_key", arch_val) + + cn_config = cn_full_config.get(controlnet_key, []) + filepath = "None" + if selected_series and selected_type: + for model in cn_config: + if model.get("Series") == selected_series and selected_type in model.get("Type", []): + filepath = model.get("Filepath") + break + return filepath + + for i in range(MAX_CONTROLNETS): + cn_types[i].change( + fn=on_cn_type_change, + inputs=[cn_types[i], actual_arch_comp], + outputs=[cn_series[i], cn_filepaths[i]], + show_progress=False + ) + cn_series[i].change( + fn=on_cn_series_change, + inputs=[cn_series[i], cn_types[i], actual_arch_comp], + outputs=[cn_filepaths[i]], + show_progress=False + ) + + def on_accordion_expand(*images): + return [gr.update() for _ in images] + + accordion.expand( + fn=on_accordion_expand, + inputs=cn_images, + outputs=cn_images, + show_progress=False + ) + + def create_flux1_ipadapter_event_handlers(prefix): + fipa_rows = ui_components.get(f'flux1_ipadapter_rows_{prefix}') + if not fipa_rows: return + count_state = ui_components[f'flux1_ipadapter_count_state_{prefix}'] + add_button = ui_components[f'add_flux1_ipadapter_button_{prefix}'] + del_button = ui_components[f'delete_flux1_ipadapter_button_{prefix}'] + + def add_fipa_row(c): + c += 1 + return { + count_state: c, + fipa_rows[c - 1]: gr.update(visible=True), + add_button: gr.update(visible=c < MAX_IPADAPTERS), + del_button: gr.update(visible=True), + } + + def del_fipa_row(c): + c -= 1 + return { + count_state: c, + fipa_rows[c]: gr.update(visible=False), + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0), + } + + add_outputs = [count_state, add_button, del_button] + fipa_rows + del_outputs = [count_state, add_button, del_button] + fipa_rows + add_button.click(fn=add_fipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_fipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def create_style_event_handlers(prefix): + style_rows = ui_components.get(f'style_rows_{prefix}') + if not style_rows: return + count_state = ui_components[f'style_count_state_{prefix}'] + add_button = ui_components[f'add_style_button_{prefix}'] + del_button = ui_components[f'delete_style_button_{prefix}'] + + def add_style_row(c): + c += 1 + return { + count_state: c, + style_rows[c - 1]: gr.update(visible=True), + add_button: gr.update(visible=c < 5), + del_button: gr.update(visible=True), + } + + def del_style_row(c): + c -= 1 + return { + count_state: c, + style_rows[c]: gr.update(visible=False), + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0), + } + + add_outputs = [count_state, add_button, del_button] + style_rows + del_outputs = [count_state, add_button, del_button] + style_rows + add_button.click(fn=add_style_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_style_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def create_ipadapter_event_handlers(prefix): + ipa_rows = ui_components.get(f'ipadapter_rows_{prefix}') + if not ipa_rows: return + ipa_lora_strengths = ui_components[f'ipadapter_lora_strengths_{prefix}'] + ipa_final_preset = ui_components[f'ipadapter_final_preset_{prefix}'] + ipa_final_lora_strength = ui_components[f'ipadapter_final_lora_strength_{prefix}'] + count_state = ui_components[f'ipadapter_count_state_{prefix}'] + add_button = ui_components[f'add_ipadapter_button_{prefix}'] + del_button = ui_components[f'delete_ipadapter_button_{prefix}'] + accordion = ui_components[f'ipadapter_accordion_{prefix}'] + + def add_ipa_row(c): + c += 1 + return { + count_state: c, + ipa_rows[c - 1]: gr.update(visible=True), + add_button: gr.update(visible=c < MAX_IPADAPTERS), + del_button: gr.update(visible=True), + } + + def del_ipa_row(c): + c -= 1 + return { + count_state: c, + ipa_rows[c]: gr.update(visible=False), + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0), + } + + add_outputs = [count_state, add_button, del_button] + ipa_rows + del_outputs = [count_state, add_button, del_button] + ipa_rows + add_button.click(fn=add_ipa_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_ipa_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def on_preset_change(preset_value): + config = load_ipadapter_config() + faceid_presets = [] + if config: + faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SDXL", [])) + faceid_presets.extend(config.get("IPAdapter_FaceID_presets", {}).get("SD1.5", [])) + + is_visible = preset_value in faceid_presets + updates = [gr.update(visible=is_visible)] * (MAX_IPADAPTERS + 1) + return updates + + all_lora_strength_sliders = [ipa_final_lora_strength] + ipa_lora_strengths + ipa_final_preset.change(fn=on_preset_change, inputs=[ipa_final_preset], outputs=all_lora_strength_sliders, show_progress=False) + + accordion.expand(fn=lambda *imgs: [gr.update() for _ in imgs], inputs=ui_components[f'ipadapter_images_{prefix}'], outputs=ui_components[f'ipadapter_images_{prefix}'], show_progress=False) + + def create_reference_latent_event_handlers(prefix): + ref_rows = ui_components.get(f'reference_latent_rows_{prefix}') + if not ref_rows: return + count_state = ui_components[f'reference_latent_count_state_{prefix}'] + add_button = ui_components[f'add_reference_latent_button_{prefix}'] + del_button = ui_components[f'delete_reference_latent_button_{prefix}'] + images = ui_components[f'reference_latent_images_{prefix}'] + + def add_ref_row(c): + c += 1 + return { + count_state: c, + ref_rows[c - 1]: gr.update(visible=True), + add_button: gr.update(visible=c < 10), + del_button: gr.update(visible=True), + } + + def del_ref_row(c): + c -= 1 + return { + count_state: c, + ref_rows[c]: gr.update(visible=False), + images[c]: None, + add_button: gr.update(visible=True), + del_button: gr.update(visible=c > 0), + } + + add_outputs = [count_state, add_button, del_button] + ref_rows + del_outputs = [count_state, add_button, del_button] + ref_rows + images + add_button.click(fn=add_ref_row, inputs=[count_state], outputs=add_outputs, show_progress=False) + del_button.click(fn=del_ref_row, inputs=[count_state], outputs=del_outputs, show_progress=False) + + def create_embedding_event_handlers(prefix): - rows = ui_components[f'embedding_rows_{prefix}'] + rows = ui_components.get(f'embedding_rows_{prefix}') + if not rows: return ids = ui_components[f'embeddings_ids_{prefix}'] files = ui_components[f'embeddings_files_{prefix}'] count_state = ui_components[f'embedding_count_state_{prefix}'] @@ -224,7 +621,8 @@ def attach_event_handlers(ui_components, demo): del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def create_conditioning_event_handlers(prefix): - rows = ui_components[f'conditioning_rows_{prefix}'] + rows = ui_components.get(f'conditioning_rows_{prefix}') + if not rows: return prompts = ui_components[f'conditioning_prompts_{prefix}'] count_state = ui_components[f'conditioning_count_state_{prefix}'] add_button = ui_components[f'add_conditioning_button_{prefix}'] @@ -253,37 +651,6 @@ def attach_event_handlers(ui_components, demo): del_outputs = [count_state, add_button, del_button] + rows + prompts add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False) del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False) - - def create_reference_latent_event_handlers(prefix): - rows = ui_components[f'reference_latent_rows_{prefix}'] - images = ui_components[f'reference_latent_images_{prefix}'] - count_state = ui_components[f'reference_latent_count_state_{prefix}'] - add_button = ui_components[f'add_reference_latent_button_{prefix}'] - del_button = ui_components[f'delete_reference_latent_button_{prefix}'] - - def add_row(c): - c += 1 - return { - count_state: c, - rows[c - 1]: gr.update(visible=True), - add_button: gr.update(visible=c < MAX_REFERENCE_LATENTS), - del_button: gr.update(visible=True), - } - - def del_row(c): - c -= 1 - return { - count_state: c, - rows[c]: gr.update(visible=False), - images[c]: None, - add_button: gr.update(visible=True), - del_button: gr.update(visible=c > 0), - } - - add_outputs = [count_state, add_button, del_button] + rows - del_outputs = [count_state, add_button, del_button] + rows + images - add_button.click(fn=add_row, inputs=[count_state], outputs=add_outputs, show_progress=False) - del_button.click(fn=del_row, inputs=[count_state], outputs=del_outputs, show_progress=False) def on_vae_upload(file_obj): if not file_obj: @@ -310,37 +677,48 @@ def attach_event_handlers(ui_components, demo): def create_run_event(prefix: str, task_type: str): run_inputs_map = { 'model_display_name': ui_components[f'base_model_{prefix}'], - 'positive_prompt': ui_components[f'prompt_{prefix}'], - 'negative_prompt': ui_components[f'neg_prompt_{prefix}'], - 'seed': ui_components[f'seed_{prefix}'], - 'batch_size': ui_components[f'batch_size_{prefix}'], - 'guidance_scale': ui_components[f'cfg_{prefix}'], - 'num_inference_steps': ui_components[f'steps_{prefix}'], - 'sampler': ui_components[f'sampler_{prefix}'], - 'scheduler': ui_components[f'scheduler_{prefix}'], - 'zero_gpu_duration': ui_components[f'zero_gpu_{prefix}'], - 'civitai_api_key': ui_components.get(f'civitai_api_key_{prefix}'), - 'clip_skip': ui_components[f'clip_skip_{prefix}'], + 'positive_prompt': ui_components.get(f'prompt_{prefix}') or ui_components.get(f'{prefix}_positive_prompt'), + 'negative_prompt': ui_components.get(f'neg_prompt_{prefix}') or ui_components.get(f'{prefix}_negative_prompt'), + 'seed': ui_components.get(f'seed_{prefix}') or ui_components.get(f'{prefix}_seed'), + 'batch_size': ui_components.get(f'batch_size_{prefix}') or ui_components.get(f'{prefix}_batch_size'), + 'guidance_scale': ui_components.get(f'cfg_{prefix}') or ui_components.get(f'{prefix}_cfg'), + 'num_inference_steps': ui_components.get(f'steps_{prefix}') or ui_components.get(f'{prefix}_steps'), + 'sampler': ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name'), + 'scheduler': ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler'), + 'zero_gpu_duration': ui_components.get(f'zero_gpu_{prefix}'), + + 'clip_skip': ui_components.get(f'clip_skip_{prefix}'), + 'guidance': ui_components.get(f'guidance_{prefix}'), 'task_type': gr.State(task_type) } if task_type not in ['img2img', 'inpaint']: - run_inputs_map.update({'width': ui_components[f'width_{prefix}'], 'height': ui_components[f'height_{prefix}']}) + run_inputs_map.update({ + 'width': ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width'), + 'height': ui_components.get(f'height_{prefix}') or ui_components.get(f'{prefix}_height') + }) task_specific_map = { 'img2img': {'img2img_image': f'input_image_{prefix}', 'img2img_denoise': f'denoise_{prefix}'}, - 'inpaint': {'inpaint_image_dict': f'input_image_dict_{prefix}'}, - 'outpaint': {'outpaint_image': f'input_image_{prefix}', 'outpaint_left': f'outpaint_left_{prefix}', 'outpaint_top': f'outpaint_top_{prefix}', 'outpaint_right': f'outpaint_right_{prefix}', 'outpaint_bottom': f'outpaint_bottom_{prefix}'}, + 'inpaint': {'inpaint_image_dict': f'input_image_dict_{prefix}', 'grow_mask_by': f'grow_mask_by_{prefix}'}, + 'outpaint': {'outpaint_image': f'input_image_{prefix}', 'left': f'left_{prefix}', 'top': f'top_{prefix}', 'right': f'right_{prefix}', 'bottom': f'bottom_{prefix}', 'feathering': f'feathering_{prefix}'}, 'hires_fix': {'hires_image': f'input_image_{prefix}', 'hires_upscaler': f'hires_upscaler_{prefix}', 'hires_scale_by': f'hires_scale_by_{prefix}', 'hires_denoise': f'denoise_{prefix}'} } if task_type in task_specific_map: for key, comp_name in task_specific_map[task_type].items(): - run_inputs_map[key] = ui_components[comp_name] + if comp_name in ui_components: + run_inputs_map[key] = ui_components[comp_name] lora_data_components = ui_components.get(f'all_lora_components_flat_{prefix}', []) + controlnet_data_components = ui_components.get(f'all_controlnet_components_flat_{prefix}', []) + diffsynth_controlnet_data_components = ui_components.get(f'all_diffsynth_controlnet_components_flat_{prefix}', []) + ipadapter_data_components = ui_components.get(f'all_ipadapter_components_flat_{prefix}', []) + sd3_ipadapter_data_components = ui_components.get(f'all_sd3_ipadapter_components_flat_{prefix}', []) + flux1_ipadapter_data_components = ui_components.get(f'all_flux1_ipadapter_components_flat_{prefix}', []) + style_data_components = ui_components.get(f'all_style_components_flat_{prefix}', []) embedding_data_components = ui_components.get(f'all_embedding_components_flat_{prefix}', []) conditioning_data_components = ui_components.get(f'all_conditioning_components_flat_{prefix}', []) - reference_latent_components = ui_components.get(f'all_reference_latent_components_flat_{prefix}', []) + reference_latent_data_components = ui_components.get(f'all_reference_latent_components_flat_{prefix}', []) run_inputs_map['vae_source'] = ui_components.get(f'vae_source_{prefix}') run_inputs_map['vae_id'] = ui_components.get(f'vae_id_{prefix}') @@ -348,153 +726,533 @@ def attach_event_handlers(ui_components, demo): input_keys = list(run_inputs_map.keys()) input_list_flat = [v for v in run_inputs_map.values() if v is not None] - input_list_flat += lora_data_components + embedding_data_components + conditioning_data_components + reference_latent_components + all_chains = [ + lora_data_components, controlnet_data_components, diffsynth_controlnet_data_components, ipadapter_data_components, + sd3_ipadapter_data_components, flux1_ipadapter_data_components, style_data_components, + embedding_data_components, conditioning_data_components, reference_latent_data_components + ] + for chain in all_chains: + if chain: + input_list_flat.extend(chain) def create_ui_inputs_dict(*args): valid_keys = [k for k in input_keys if run_inputs_map[k] is not None] ui_dict = dict(zip(valid_keys, args[:len(valid_keys)])) arg_idx = len(valid_keys) - - ui_dict['lora_data'] = list(args[arg_idx : arg_idx + len(lora_data_components)]) - arg_idx += len(lora_data_components) - ui_dict['embedding_data'] = list(args[arg_idx : arg_idx + len(embedding_data_components)]) - arg_idx += len(embedding_data_components) - ui_dict['conditioning_data'] = list(args[arg_idx : arg_idx + len(conditioning_data_components)]) - arg_idx += len(conditioning_data_components) - ui_dict['reference_latent_data'] = list(args[arg_idx : arg_idx + len(reference_latent_components)]) + def assign_chain_data(chain_key, components_list): + nonlocal arg_idx + if components_list: + ui_dict[chain_key] = list(args[arg_idx : arg_idx + len(components_list)]) + arg_idx += len(components_list) + + assign_chain_data('lora_data', lora_data_components) + assign_chain_data('controlnet_data', controlnet_data_components) + assign_chain_data('diffsynth_controlnet_data', diffsynth_controlnet_data_components) + assign_chain_data('ipadapter_data', ipadapter_data_components) + assign_chain_data('sd3_ipadapter_chain', sd3_ipadapter_data_components) + assign_chain_data('flux1_ipadapter_data', flux1_ipadapter_data_components) + assign_chain_data('style_data', style_data_components) + assign_chain_data('embedding_data', embedding_data_components) + assign_chain_data('conditioning_data', conditioning_data_components) + assign_chain_data('reference_latent_data', reference_latent_data_components) return ui_dict - ui_components[f'run_{prefix}'].click( - fn=lambda *args, progress=gr.Progress(track_tqdm=True): generate_image_wrapper(create_ui_inputs_dict(*args), progress), - inputs=input_list_flat, - outputs=[ui_components[f'result_{prefix}']] - ) + run_btn = ui_components.get(f'run_{prefix}') or ui_components.get(f'{prefix}_run_button') + res_gal = ui_components.get(f'result_{prefix}') or ui_components.get(f'{prefix}_output_gallery') + if run_btn and res_gal: + run_btn.click( + fn=lambda *args, progress=gr.Progress(track_tqdm=True): generate_image_wrapper(create_ui_inputs_dict(*args), progress), + inputs=input_list_flat, + outputs=[res_gal] + ) + + def make_update_fn(m_comp, cat_comp, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, ipa_preset, lora_acc, cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp): + def update_fn(*args): + arch = args[0] + category = args[1] + current_ar = args[2] if len(args) > 2 else None + from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, FEATURES_CONFIG, ARCHITECTURES_CONFIG, MODEL_DEFAULTS_CONFIG, ARCH_CATEGORIES_MAP + from utils.app_utils import get_model_generation_defaults + + if arch == "ALL": + valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats)) + else: + valid_cats = ARCH_CATEGORIES_MAP.get(arch, []) + + cat_choices = ["ALL"] + sorted(valid_cats) + new_category = category if category in cat_choices else "ALL" + + choices = [] + for name, info in MODEL_MAP_CHECKPOINT.items(): + m_arch = info[2] + m_cat = info[4] if len(info) > 4 else None + arch_match = (arch == "ALL" or m_arch == arch) + cat_match = (new_category == "ALL" or m_cat == new_category) + if arch_match and cat_match: + choices.append(name) + + val = choices[0] if choices else None + + updates = { + m_comp: gr.update(choices=choices, value=val), + cat_comp: gr.update(choices=cat_choices, value=new_category) + } + + m_type = MODEL_TYPE_MAP.get(val, "SDXL") if val 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_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {})) + enabled_chains = arch_features.get('enabled_chains', []) + + if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains)) + if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains)) + if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains)) + if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains)) + if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains)) + if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains)) + if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains)) + if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains)) + if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains)) + if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains)) + + if cs_comp: + updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15")) + if guidance_comp: + updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1")) + + if ar_comp: + res_key = arch_model_type + if res_key not in RESOLUTION_MAP: + res_key = 'sdxl' + res_map = RESOLUTION_MAP.get(res_key, {}) + target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)") + updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar) + if width_comp and height_comp and target_ar in res_map: + updates[width_comp] = gr.update(value=res_map[target_ar][0]) + updates[height_comp] = gr.update(value=res_map[target_ar][1]) + + controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type) + + all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key) + for t_comp in cn_types: + updates[t_comp] = gr.update(choices=all_types, value=default_type) + for s_comp in cn_series: + updates[s_comp] = gr.update(choices=series_choices, value=default_series) + for f_comp in cn_filepaths: + updates[f_comp] = filepath + + diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key) + for t_comp in diffsynth_cn_types: + updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type) + for s_comp in diffsynth_cn_series: + updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series) + for f_comp in diffsynth_cn_filepaths: + updates[f_comp] = diffsynth_filepath + + if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]): + config = load_ipadapter_config() + ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5" + std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, []) + face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, []) + all_ipa_presets = std_presets + face_presets + default_ipa = all_ipa_presets[0] if all_ipa_presets else None + updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa) + + defaults = get_model_generation_defaults(val, arch_model_type, MODEL_DEFAULTS_CONFIG) + if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps')) + if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg')) + if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name')) + if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler')) + if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt')) + if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt')) + + return updates + return update_fn + + def make_model_change_fn(cat_comp_ref, cs_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, diffsynth_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp): + def change_fn(*args): + model_name = args[0] + idx = 1 + current_arch = args[idx] if arch_comp_ref and idx < len(args) else None + if arch_comp_ref: idx += 1 + current_cat = args[idx] if cat_comp_ref and idx < len(args) else None + if cat_comp_ref: idx += 1 + current_ar = args[idx] if idx < len(args) else None + from core.settings import MODEL_TYPE_MAP, FEATURES_CONFIG, ARCHITECTURES_CONFIG, MODEL_DEFAULTS_CONFIG, ARCH_CATEGORIES_MAP, MODEL_MAP_CHECKPOINT + from utils.app_utils import get_model_generation_defaults + m_type = MODEL_TYPE_MAP.get(model_name, "SDXL") + + m_info = MODEL_MAP_CHECKPOINT.get(model_name) + m_cat = m_info[4] if m_info and len(m_info) > 4 else None + if not m_cat: m_cat = "ALL" + + updates = {} + target_arch = m_type + if arch_comp_ref: + if current_arch == "ALL": + updates[arch_comp_ref] = gr.update() + target_arch = "ALL" + else: + updates[arch_comp_ref] = m_type + + if cat_comp_ref: + if target_arch == "ALL": + valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats)) + else: + valid_cats = ARCH_CATEGORIES_MAP.get(target_arch, []) + cat_choices = ["ALL"] + sorted(valid_cats) + + if current_cat == "ALL": + updates[cat_comp_ref] = gr.update(choices=cat_choices) + else: + updates[cat_comp_ref] = gr.update(choices=cat_choices, value=m_cat) + + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", "")) + + arch_features = FEATURES_CONFIG.get(arch_model_type, FEATURES_CONFIG.get('default', {})) + enabled_chains = arch_features.get('enabled_chains', []) + + if lora_acc: updates[lora_acc] = gr.update(visible=('lora' in enabled_chains)) + if cn_acc: updates[cn_acc] = gr.update(visible=('controlnet' in enabled_chains)) + if diffsynth_cn_acc: updates[diffsynth_cn_acc] = gr.update(visible=('controlnet_model_patch' in enabled_chains)) + if ipa_acc: updates[ipa_acc] = gr.update(visible=('ipadapter' in enabled_chains)) + if flux1_ipa_acc: updates[flux1_ipa_acc] = gr.update(visible=('flux1_ipadapter' in enabled_chains)) + if sd3_ipa_acc: updates[sd3_ipa_acc] = gr.update(visible=('sd3_ipadapter' in enabled_chains)) + if style_acc: updates[style_acc] = gr.update(visible=('style' in enabled_chains)) + if embed_acc: updates[embed_acc] = gr.update(visible=('embedding' in enabled_chains)) + if cond_acc: updates[cond_acc] = gr.update(visible=('conditioning' in enabled_chains)) + if ref_latent_acc: updates[ref_latent_acc] = gr.update(visible=('reference_latent' in enabled_chains)) + + if cs_comp: + updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15")) + if guidance_comp: + updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1")) + + if ar_comp: + res_key = arch_model_type + if res_key not in RESOLUTION_MAP: + res_key = 'sdxl' + res_map = RESOLUTION_MAP.get(res_key, {}) + target_ar = current_ar if current_ar in res_map else (list(res_map.keys())[0] if res_map else "1:1 (Square)") + updates[ar_comp] = gr.update(choices=list(res_map.keys()), value=target_ar) + if width_comp and height_comp and target_ar in res_map: + updates[width_comp] = gr.update(value=res_map[target_ar][0]) + updates[height_comp] = gr.update(value=res_map[target_ar][1]) + + controlnet_key = architectures_dict.get(m_type, {}).get("controlnet_key", m_type) + + all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key) + for t_comp in cn_types: + updates[t_comp] = gr.update(choices=all_types, value=default_type) + for s_comp in cn_series: + updates[s_comp] = gr.update(choices=series_choices, value=default_series) + for f_comp in cn_filepaths: + updates[f_comp] = filepath + + diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key) + for t_comp in diffsynth_cn_types: + updates[t_comp] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type) + for s_comp in diffsynth_cn_series: + updates[s_comp] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series) + for f_comp in diffsynth_cn_filepaths: + updates[f_comp] = diffsynth_filepath + + if ipa_preset and (arch_model_type in ["sdxl", "sd15", "sd35"]): + config = load_ipadapter_config() + ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5" + std_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, []) + face_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, []) + all_ipa_presets = std_presets + face_presets + default_ipa = all_ipa_presets[0] if all_ipa_presets else None + updates[ipa_preset] = gr.update(choices=all_ipa_presets, value=default_ipa) + + defaults = get_model_generation_defaults(model_name, arch_model_type, MODEL_DEFAULTS_CONFIG) + if steps_comp: updates[steps_comp] = gr.update(value=defaults.get('steps')) + if cfg_comp: updates[cfg_comp] = gr.update(value=defaults.get('cfg')) + if sampler_comp: updates[sampler_comp] = gr.update(value=defaults.get('sampler_name')) + if scheduler_comp: updates[scheduler_comp] = gr.update(value=defaults.get('scheduler')) + if prompt_comp: updates[prompt_comp] = gr.update(value=defaults.get('positive_prompt')) + if neg_prompt_comp: updates[neg_prompt_comp] = gr.update(value=defaults.get('negative_prompt')) + + return updates + return change_fn for prefix, task_type in [ ("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"), ("outpaint", "outpaint"), ("hires_fix", "hires_fix"), ]: - model_dropdown = ui_components.get(f'base_model_{prefix}') - steps_slider = ui_components.get(f'steps_{prefix}') - cfg_slider = ui_components.get(f'cfg_{prefix}') - if all([model_dropdown, steps_slider, cfg_slider]): - model_dropdown.change( - fn=on_model_change, - inputs=[model_dropdown], - outputs=[steps_slider, cfg_slider], - show_progress=False - ) - if f'add_lora_button_{prefix}' in ui_components: - create_lora_event_handlers(prefix) - lora_uploads = ui_components[f'lora_uploads_{prefix}'] - lora_ids = ui_components[f'lora_ids_{prefix}'] - lora_sources = ui_components[f'lora_sources_{prefix}'] - for i in range(MAX_LORAS): - lora_uploads[i].upload( - fn=on_lora_upload, - inputs=[lora_uploads[i]], - outputs=[lora_ids[i], lora_sources[i]], - show_progress=False - ) + 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}') + clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip') + guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance') + 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}', []) + + diffsynth_cn_types_list = ui_components.get(f'diffsynth_controlnet_types_{prefix}', []) + diffsynth_cn_series_list = ui_components.get(f'diffsynth_controlnet_series_{prefix}', []) + diffsynth_cn_filepaths_list = ui_components.get(f'diffsynth_controlnet_filepaths_{prefix}', []) + + lora_accordion = ui_components.get(f'lora_accordion_{prefix}') + cn_accordion = ui_components.get(f'controlnet_accordion_{prefix}') + diffsynth_cn_accordion = ui_components.get(f'diffsynth_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}') + + 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 clip_skip_comp: outputs.append(clip_skip_comp) + if guidance_comp: outputs.append(guidance_comp) + if aspect_ratio_comp: outputs.append(aspect_ratio_comp) + outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list) + outputs.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list) + if lora_accordion: outputs.append(lora_accordion) + if cn_accordion: outputs.append(cn_accordion) + if diffsynth_cn_accordion: outputs.append(diffsynth_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 ipa_preset_list: outputs.append(ipa_preset_list) + + outputs.extend(valid_extra_comps) + + update_fn = make_update_fn( + model_comp, cat_comp, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp, + cn_types_list, cn_series_list, cn_filepaths_list, + diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list, + ipa_preset_list, lora_accordion, cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, + ref_latent_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp + ) + inputs = [arch_comp, cat_comp] + if aspect_ratio_comp: + inputs.append(aspect_ratio_comp) + arch_comp.change(fn=update_fn, inputs=inputs, outputs=outputs) + cat_comp.change(fn=update_fn, inputs=inputs, outputs=outputs) - if f'add_embedding_button_{prefix}' in ui_components: - create_embedding_event_handlers(prefix) - if f'embeddings_uploads_{prefix}' in ui_components: - emb_uploads = ui_components[f'embeddings_uploads_{prefix}'] - emb_ids = ui_components[f'embeddings_ids_{prefix}'] - emb_sources = ui_components[f'embeddings_sources_{prefix}'] - emb_files = ui_components[f'embeddings_files_{prefix}'] - for i in range(MAX_EMBEDDINGS): - emb_uploads[i].upload( - fn=on_embedding_upload, - inputs=[emb_uploads[i]], - outputs=[emb_ids[i], emb_sources[i], emb_files[i]], - show_progress=False - ) - if f'add_conditioning_button_{prefix}' in ui_components: create_conditioning_event_handlers(prefix) - if f'add_reference_latent_button_{prefix}' in ui_components: create_reference_latent_event_handlers(prefix) - if f'vae_source_{prefix}' in ui_components: - upload_button = ui_components.get(f'vae_upload_button_{prefix}') - if upload_button: - upload_button.upload( - fn=on_vae_upload, - inputs=[upload_button], - outputs=[ - ui_components[f'vae_id_{prefix}'], - ui_components[f'vae_source_{prefix}'], - ui_components[f'vae_file_{prefix}'] - ] + if model_comp: + outputs2 = [] + if arch_comp: outputs2.append(arch_comp) + if cat_comp: outputs2.append(cat_comp) + if clip_skip_comp: outputs2.append(clip_skip_comp) + if guidance_comp: outputs2.append(guidance_comp) + if aspect_ratio_comp: outputs2.append(aspect_ratio_comp) + outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list) + outputs2.extend(diffsynth_cn_types_list + diffsynth_cn_series_list + diffsynth_cn_filepaths_list) + if lora_accordion: outputs2.append(lora_accordion) + if cn_accordion: outputs2.append(cn_accordion) + if diffsynth_cn_accordion: outputs2.append(diffsynth_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 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, clip_skip_comp, aspect_ratio_comp, width_comp, height_comp, + cn_types_list, cn_series_list, cn_filepaths_list, + diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list, + arch_comp, ipa_preset_list, lora_accordion, cn_accordion, diffsynth_cn_accordion, ipa_accordion, sd3_ipa_accordion, flux1_ipa_accordion, style_accordion, embedding_accordion, conditioning_accordion, + ref_latent_accordion, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp ) + model_comp.change(fn=change_fn, inputs=inputs2, outputs=outputs2) + create_lora_event_handlers(prefix) + create_controlnet_event_handlers(prefix) + create_diffsynth_controlnet_event_handlers(prefix) + create_ipadapter_event_handlers(prefix) + create_embedding_event_handlers(prefix) + create_conditioning_event_handlers(prefix) + create_flux1_ipadapter_event_handlers(prefix) + create_style_event_handlers(prefix) + create_reference_latent_event_handlers(prefix) create_run_event(prefix, task_type) - def on_aspect_ratio_change(ratio_key, model_display_name): - model_type = MODEL_TYPE_MAP.get(model_display_name, 'sdxl').lower() - res_map = RESOLUTION_MAP.get(model_type, RESOLUTION_MAP.get("sdxl", {})) - w, h = res_map.get(ratio_key, (1024, 1024)) - return w, h - for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: - if f'aspect_ratio_{prefix}' in ui_components: - aspect_ratio_dropdown = ui_components[f'aspect_ratio_{prefix}'] - width_component = ui_components[f'width_{prefix}'] - height_component = ui_components[f'height_{prefix}'] - model_dropdown = ui_components[f'base_model_{prefix}'] - aspect_ratio_dropdown.change(fn=on_aspect_ratio_change, inputs=[aspect_ratio_dropdown, model_dropdown], outputs=[width_component, height_component], 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 - return { - ui_components['model_and_run_row_inpaint']: gr.update(visible=other_elements_visible), + + 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 = [ - ui_components['model_and_run_row_inpaint'], ui_components['prompts_column_inpaint'], - ui_components['params_and_gallery_row_inpaint'], ui_components['accordion_wrapper_inpaint'], + 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) + ]) + + ui_components['view_mode_inpaint'].change( + fn=toggle_inpaint_fullscreen_view, + inputs=[ui_components['view_mode_inpaint']], + outputs=output_components, + show_progress=False + ) - def run_on_load(): - all_updates = {} + def initialize_all_cn_dropdowns(): + from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, ARCHITECTURES_CONFIG + default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None + default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL" + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + controlnet_key = architectures_dict.get(default_m_type, {}).get("controlnet_key", default_m_type) - default_preprocessor = "Canny Edge" - model_update = update_preprocessor_models_dropdown(default_preprocessor) - all_updates[ui_components["preprocessor_model_cn"]] = model_update + all_types, default_type, series_choices, default_series, filepath = get_cn_defaults(controlnet_key) + diffsynth_all_types, diffsynth_default_type, diffsynth_series_choices, diffsynth_default_series, diffsynth_filepath = get_diffsynth_cn_defaults(controlnet_key) - settings_outputs = update_preprocessor_settings_ui(default_preprocessor) - dynamic_outputs = ui_components["cn_sliders"] + ui_components["cn_dropdowns"] + ui_components["cn_checkboxes"] - for i, comp in enumerate(dynamic_outputs): - all_updates[comp] = settings_outputs[i] + updates = {} + for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: + if f'controlnet_types_{prefix}' in ui_components: + for type_dd in ui_components[f'controlnet_types_{prefix}']: + updates[type_dd] = gr.update(choices=all_types, value=default_type) + for series_dd in ui_components[f'controlnet_series_{prefix}']: + updates[series_dd] = gr.update(choices=series_choices, value=default_series) + for filepath_state in ui_components[f'controlnet_filepaths_{prefix}']: + updates[filepath_state] = filepath + + if f'diffsynth_controlnet_types_{prefix}' in ui_components: + for type_dd in ui_components[f'diffsynth_controlnet_types_{prefix}']: + updates[type_dd] = gr.update(choices=diffsynth_all_types, value=diffsynth_default_type) + for series_dd in ui_components[f'diffsynth_controlnet_series_{prefix}']: + updates[series_dd] = gr.update(choices=diffsynth_series_choices, value=diffsynth_default_series) + for filepath_state in ui_components[f'diffsynth_controlnet_filepaths_{prefix}']: + updates[filepath_state] = diffsynth_filepath + + return updates - run_button_update, zero_gpu_update = update_run_button_for_cpu(default_preprocessor) - all_updates[ui_components["run_cn"]] = run_button_update - all_updates[ui_components["zero_gpu_cn"]] = zero_gpu_update + def initialize_all_ipa_dropdowns(): + config = load_ipadapter_config() + if not config: return {} + + from core.settings import MODEL_TYPE_MAP, MODEL_MAP_CHECKPOINT, ARCHITECTURES_CONFIG + default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None + default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL" + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + arch_model_type = architectures_dict.get(default_m_type, {}).get("model_type", default_m_type.lower().replace(" ", "").replace(".", "")) + ipa_arch_key = "SDXL" if arch_model_type in ["sdxl", "sd35"] else "SD1.5" + + unified_presets = config.get("IPAdapter_presets", {}).get(ipa_arch_key, []) + faceid_presets = config.get("IPAdapter_FaceID_presets", {}).get(ipa_arch_key, []) + + all_presets = unified_presets + faceid_presets + default_preset = all_presets[0] if all_presets else None + is_faceid_default = default_preset in faceid_presets + + lora_strength_update = gr.update(visible=is_faceid_default) + + updates = {} + for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: + if f'ipadapter_final_preset_{prefix}' in ui_components: + for lora_strength_slider in ui_components[f'ipadapter_lora_strengths_{prefix}']: + updates[lora_strength_slider] = lora_strength_update + updates[ui_components[f'ipadapter_final_preset_{prefix}']] = gr.update(choices=all_presets, value=default_preset) + updates[ui_components[f'ipadapter_final_lora_strength_{prefix}']] = lora_strength_update + return updates + + def run_on_load(): + cn_updates = initialize_all_cn_dropdowns() + ipa_updates = initialize_all_ipa_dropdowns() + + all_updates = {**cn_updates, **ipa_updates} return all_updates - all_load_outputs = [ - ui_components["preprocessor_model_cn"], - *ui_components["cn_sliders"], - *ui_components["cn_dropdowns"], - *ui_components["cn_checkboxes"], - ui_components["run_cn"], - ui_components["zero_gpu_cn"] - ] + all_load_outputs = [] + for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: + 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'diffsynth_controlnet_types_{prefix}' in ui_components: + all_load_outputs.extend(ui_components[f'diffsynth_controlnet_types_{prefix}']) + all_load_outputs.extend(ui_components[f'diffsynth_controlnet_series_{prefix}']) + all_load_outputs.extend(ui_components[f'diffsynth_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=run_on_load, outputs=all_load_outputs - ) \ No newline at end of file + ) + + def on_aspect_ratio_change(ratio_key, model_display_name): + from core.settings import MODEL_TYPE_MAP, ARCHITECTURES_CONFIG + m_type = MODEL_TYPE_MAP.get(model_display_name, 'SDXL') + architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) + arch_model_type = architectures_dict.get(m_type, {}).get("model_type", m_type.lower().replace(" ", "").replace(".", "")) + + res_map = RESOLUTION_MAP.get(arch_model_type, RESOLUTION_MAP.get("sdxl", {})) + w, h = res_map.get(ratio_key, (1024, 1024)) + return w, h + + for prefix in ["txt2img", "img2img", "inpaint", "outpaint", "hires_fix"]: + 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) \ No newline at end of file diff --git a/ui/layout.py b/ui/layout.py index 1d16fa4a01e2af043a48e83d416bf82a112b4b61..c685cd86ab9c6106c45098cf554a50c407f37093 100644 --- a/ui/layout.py +++ b/ui/layout.py @@ -6,82 +6,37 @@ from .shared import txt2img_ui, img2img_ui, inpaint_ui, outpaint_ui, hires_fix_u MAX_DYNAMIC_CONTROLS = 10 -def get_preprocessor_choices(): - from nodes import NODE_DISPLAY_NAME_MAPPINGS - - preprocessor_names = [ - display_name for class_name, display_name in NODE_DISPLAY_NAME_MAPPINGS.items() - if "Preprocessor" in class_name or "Segmentor" in class_name or - "Estimator" in class_name or "Detector" in class_name - ] - return sorted(list(set(preprocessor_names))) - - def build_ui(event_handler_function): ui_components = {} with gr.Blocks() as demo: - gr.Markdown("# ImageGen - FLUX.2") + gr.Markdown("# ImageGen - FLUX.2-KV") gr.Markdown( "This demo is a streamlined version of the [Comfy web UI](https://github.com/RioShiina47/comfy-webui)'s [ImageGen](https://huggingface.co/spaces/RioShiina/ImageGen) functionality. " "Other versions are also available: " - "[Z-Image](https://huggingface.co/spaces/RioShiina/ImageGen-Z-Image), " - "[Qwen-Image](https://huggingface.co/spaces/RioShiina/ImageGen-Qwen-Image), " "[Anima](https://huggingface.co/spaces/RioShiina/ImageGen-Anima), " "[Illustrious](https://huggingface.co/spaces/RioShiina/ImageGen-Illustrious), " "[NoobAI](https://huggingface.co/spaces/RioShiina/ImageGen-NoobAI), " "[Pony](https://huggingface.co/spaces/RioShiina/ImageGen-Pony)" ) with gr.Tabs(elem_id="tabs_container") as tabs: - with gr.TabItem("FLUX.2", id=0): - with gr.Tabs(elem_id="image_gen_tabs") as image_gen_tabs: - with gr.TabItem("Txt2Img", id=0): - ui_components.update(txt2img_ui.create_ui()) - - with gr.TabItem("Img2Img", id=1): - ui_components.update(img2img_ui.create_ui()) + with gr.TabItem("Txt2Img", id=0): + ui_components.update(txt2img_ui.create_ui()) + + with gr.TabItem("Img2Img", id=1): + ui_components.update(img2img_ui.create_ui()) - with gr.TabItem("Inpaint", id=2): - ui_components.update(inpaint_ui.create_ui()) + with gr.TabItem("Inpaint", id=2): + ui_components.update(inpaint_ui.create_ui()) - with gr.TabItem("Outpaint", id=3): - ui_components.update(outpaint_ui.create_ui()) + with gr.TabItem("Outpaint", id=3): + ui_components.update(outpaint_ui.create_ui()) - with gr.TabItem("Hires. Fix", id=4): - ui_components.update(hires_fix_ui.create_ui()) - - ui_components['image_gen_tabs'] = image_gen_tabs + with gr.TabItem("Hires. Fix", id=4): + ui_components.update(hires_fix_ui.create_ui()) - with gr.TabItem("Controlnet Preprocessors", id=1): - gr.Markdown("## ControlNet Auxiliary Preprocessors") - gr.Markdown("Powered by [Fannovel16/comfyui_controlnet_aux](https://github.com/Fannovel16/comfyui_controlnet_aux).") - gr.Markdown("Upload an image or video to process it with a ControlNet preprocessor.") - with gr.Row(): - with gr.Column(scale=1): - cn_input_type = gr.Radio(["Image", "Video"], label="Input Type", value="Image") - cn_image_input = gr.Image(type="pil", label="Input Image", visible=True, height=384) - cn_video_input = gr.Video(label="Input Video", visible=False) - preprocessor_cn = gr.Dropdown(label="Preprocessor", choices=get_preprocessor_choices(), value="Canny Edge") - preprocessor_model_cn = gr.Dropdown(label="Preprocessor Model", choices=[], value=None, visible=False) - with gr.Column() as preprocessor_settings_ui: - cn_sliders, cn_dropdowns, cn_checkboxes = [], [], [] - for i in range(MAX_DYNAMIC_CONTROLS): - cn_sliders.append(gr.Slider(visible=False, label=f"dyn_slider_{i}")) - cn_dropdowns.append(gr.Dropdown(visible=False, label=f"dyn_dropdown_{i}")) - cn_checkboxes.append(gr.Checkbox(visible=False, label=f"dyn_checkbox_{i}")) - run_cn = gr.Button("Run Preprocessor", variant="primary") - with gr.Column(scale=1): - output_gallery_cn = gr.Gallery(label="Output", show_label=False, object_fit="contain", height=512) - zero_gpu_cn = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional") - ui_components.update({ - "cn_input_type": cn_input_type, "cn_image_input": cn_image_input, "cn_video_input": cn_video_input, - "preprocessor_cn": preprocessor_cn, "preprocessor_model_cn": preprocessor_model_cn, "run_cn": run_cn, - "zero_gpu_cn": zero_gpu_cn, "output_gallery_cn": output_gallery_cn, - "preprocessor_settings_ui": preprocessor_settings_ui, "cn_sliders": cn_sliders, - "cn_dropdowns": cn_dropdowns, "cn_checkboxes": cn_checkboxes - }) - ui_components["tabs"] = tabs + ui_components["image_gen_tabs"] = tabs gr.Markdown("
") diff --git a/ui/shared/hires_fix_ui.py b/ui/shared/hires_fix_ui.py index a6a295aabba55524c39d28debc883d70f2b677d8..29eefc25669ae1d222b8fea94090128b1bde7778 100644 --- a/ui/shared/hires_fix_ui.py +++ b/ui/shared/hires_fix_ui.py @@ -3,8 +3,10 @@ from core.settings import MODEL_MAP_CHECKPOINT from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES from .ui_components import ( create_lora_settings_ui, - create_embedding_ui, - create_conditioning_ui, create_vae_override_ui, create_api_key_ui, + create_controlnet_ui, create_ipadapter_ui, create_embedding_ui, + create_conditioning_ui, create_vae_override_ui, + create_model_architecture_filter_ui, create_category_filter_ui, + create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui, create_reference_latent_ui ) @@ -13,12 +15,16 @@ def create_ui(): components = {} with gr.Column(): + components.update(create_model_architecture_filter_ui(prefix)) + with gr.Row(): + components.update(create_category_filter_ui(prefix)) components[f'base_model_{prefix}'] = gr.Dropdown( label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], - scale=3 + scale=3, + allow_custom_value=True ) with gr.Column(scale=1): components[f'run_{prefix}'] = gr.Button("Run Hires. Fix", variant="primary") @@ -27,8 +33,8 @@ def create_ui(): with gr.Column(scale=1): components[f'input_image_{prefix}'] = gr.Image(type="pil", label="Input Image", height=255) with gr.Column(scale=2): - components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3, placeholder="Describe the final image...") - components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3, value="") + components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3) + components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3) with gr.Row(): with gr.Column(scale=1): @@ -46,31 +52,35 @@ def create_ui(): components[f'denoise_{prefix}'] = gr.Slider(label="Denoise Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.55) with gr.Row(): - components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value="euler") - components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value="simple") + components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0]) + components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]) with gr.Row(): - components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=4) - components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=1.0) + components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28) + components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5) with gr.Row(): components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0) components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1) with gr.Row(): - components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional: Set how long to reserve the GPU.") + components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True) + components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True) + components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.") - components[f'clip_skip_{prefix}'] = gr.State(value=1) components[f'width_{prefix}'] = gr.State(value=512) components[f'height_{prefix}'] = gr.State(value=512) with gr.Column(scale=1): components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=610) - components.update(create_api_key_ui(prefix)) + components.update(create_lora_settings_ui(prefix)) - # components.update(create_diffsynth_controlnet_ui(prefix)) - # components.update(create_controlnet_ui(prefix)) - # components.update(create_embedding_ui(prefix)) - components.update(create_reference_latent_ui(prefix)) + components.update(create_controlnet_ui(prefix)) + components.update(create_ipadapter_ui(prefix)) + components.update(create_flux1_ipadapter_ui(prefix)) + components.update(create_sd3_ipadapter_ui(prefix)) + components.update(create_style_ui(prefix)) + components.update(create_embedding_ui(prefix)) components.update(create_conditioning_ui(prefix)) - # components.update(create_vae_override_ui(prefix)) + components.update(create_reference_latent_ui(prefix)) + components.update(create_vae_override_ui(prefix)) return components \ No newline at end of file diff --git a/ui/shared/img2img_ui.py b/ui/shared/img2img_ui.py index 6acee87eda55f20c9ac8009011c5015bc608dd7d..23d9febefdf89f5e2636eed3a8510b9e3fc10df2 100644 --- a/ui/shared/img2img_ui.py +++ b/ui/shared/img2img_ui.py @@ -3,8 +3,10 @@ from core.settings import MODEL_MAP_CHECKPOINT from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES from .ui_components import ( create_lora_settings_ui, - create_embedding_ui, - create_conditioning_ui, create_vae_override_ui, create_api_key_ui, + create_controlnet_ui, create_diffsynth_controlnet_ui, create_ipadapter_ui, create_embedding_ui, + create_conditioning_ui, create_vae_override_ui, + create_model_architecture_filter_ui, create_category_filter_ui, + create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui, create_reference_latent_ui ) @@ -13,8 +15,11 @@ def create_ui(): components = {} with gr.Column(): + components.update(create_model_architecture_filter_ui(prefix)) + with gr.Row(): - components[f'base_model_{prefix}'] = gr.Dropdown(label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], scale=3) + components.update(create_category_filter_ui(prefix)) + components[f'base_model_{prefix}'] = gr.Dropdown(label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], scale=3, allow_custom_value=True) with gr.Column(scale=1): components[f'run_{prefix}'] = gr.Button("Run", variant="primary") @@ -23,37 +28,41 @@ def create_ui(): components[f'input_image_{prefix}'] = gr.Image(type="pil", label="Input Image", height=255) with gr.Column(scale=2): - components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3, placeholder="Enter your prompt") - components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3, value="") + components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3) + components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3) with gr.Row(): with gr.Column(scale=1): components[f'denoise_{prefix}'] = gr.Slider(label="Denoise Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.7) with gr.Row(): - components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value="euler") - components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value="simple") + components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0]) + components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]) with gr.Row(): - components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=4) - components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=1.0) + components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28) + components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5) with gr.Row(): components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0) components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1) with gr.Row(): - components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional: Set how long to reserve the GPU. Longer jobs may need more time.") - - components[f'clip_skip_{prefix}'] = gr.State(value=1) + components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True) + components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True) + components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU. Longer jobs may need more time.") with gr.Column(scale=1): components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=505) - components.update(create_api_key_ui(prefix)) + components.update(create_lora_settings_ui(prefix)) - # components.update(create_diffsynth_controlnet_ui(prefix)) - # components.update(create_controlnet_ui(prefix)) - # components.update(create_embedding_ui(prefix)) - components.update(create_reference_latent_ui(prefix)) + components.update(create_controlnet_ui(prefix)) + components.update(create_diffsynth_controlnet_ui(prefix)) + components.update(create_ipadapter_ui(prefix)) + components.update(create_flux1_ipadapter_ui(prefix)) + components.update(create_sd3_ipadapter_ui(prefix)) + components.update(create_embedding_ui(prefix)) + components.update(create_style_ui(prefix)) components.update(create_conditioning_ui(prefix)) - # components.update(create_vae_override_ui(prefix)) + components.update(create_reference_latent_ui(prefix)) + components.update(create_vae_override_ui(prefix)) return components \ No newline at end of file diff --git a/ui/shared/inpaint_ui.py b/ui/shared/inpaint_ui.py index 80dfe46a96644565c6a5666f9b27a313c404ef0f..e45b86b55e4998d821e4be3c5e482428c1498f1c 100644 --- a/ui/shared/inpaint_ui.py +++ b/ui/shared/inpaint_ui.py @@ -2,8 +2,10 @@ import gradio as gr from core.settings import MODEL_MAP_CHECKPOINT from .ui_components import ( create_base_parameter_ui, create_lora_settings_ui, - create_embedding_ui, - create_conditioning_ui, create_vae_override_ui, create_api_key_ui, + create_controlnet_ui, create_diffsynth_controlnet_ui, create_ipadapter_ui, create_embedding_ui, + create_conditioning_ui, create_vae_override_ui, + create_model_architecture_filter_ui, create_category_filter_ui, + create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui, create_reference_latent_ui ) @@ -12,17 +14,22 @@ def create_ui(): components = {} with gr.Column(): + with gr.Row() as arch_row: + components.update(create_model_architecture_filter_ui(prefix)) + with gr.Row() as model_and_run_row: + components.update(create_category_filter_ui(prefix)) components[f'base_model_{prefix}'] = gr.Dropdown( label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], - scale=3 + scale=3, + allow_custom_value=True ) with gr.Column(scale=1): components[f'run_{prefix}'] = gr.Button("Run Inpaint", variant="primary") - components[f'model_and_run_row_{prefix}'] = model_and_run_row + components[f'model_and_run_row_{prefix}'] = [arch_row, model_and_run_row] with gr.Row() as main_content_row: with gr.Column(scale=1) as editor_column: @@ -40,44 +47,55 @@ def create_ui(): components[f'editor_column_{prefix}'] = editor_column with gr.Column(scale=2) as prompts_column: - components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=6, placeholder="Describe what to fill in the mask...") - components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=6, value="") + components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=6) + components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=6) components[f'prompts_column_{prefix}'] = prompts_column with gr.Row() as params_and_gallery_row: with gr.Column(scale=1): - param_defaults = {'w': 1024, 'h': 1024, 'cs_vis': False, 'cs_val': 1} from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES with gr.Row(): - components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value="euler") - components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value="simple") + components[f'denoise_{prefix}'] = gr.Slider( + label="Denoise", minimum=0.0, maximum=1.0, step=0.05, value=1.0 + ) + components[f'grow_mask_by_{prefix}'] = gr.Slider( + label="Grow Mask By", minimum=0, maximum=64, step=1, value=6 + ) + with gr.Row(): + components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0]) + components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]) with gr.Row(): - components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=4) - components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=1.0) + components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28) + components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5) with gr.Row(): components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0) components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1) with gr.Row(): - components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional: Set how long to reserve the GPU.") + components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True) + components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True) + components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.") - components[f'clip_skip_{prefix}'] = gr.State(value=1) components[f'width_{prefix}'] = gr.State(value=512) components[f'height_{prefix}'] = gr.State(value=512) with gr.Column(scale=1): - components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=414) + components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=510) components[f'params_and_gallery_row_{prefix}'] = params_and_gallery_row with gr.Column() as accordion_wrapper: - components.update(create_api_key_ui(prefix)) + components.update(create_lora_settings_ui(prefix)) - # components.update(create_diffsynth_controlnet_ui(prefix)) - # components.update(create_controlnet_ui(prefix)) - # components.update(create_embedding_ui(prefix)) - components.update(create_reference_latent_ui(prefix)) + components.update(create_controlnet_ui(prefix)) + components.update(create_diffsynth_controlnet_ui(prefix)) + components.update(create_ipadapter_ui(prefix)) + components.update(create_flux1_ipadapter_ui(prefix)) + components.update(create_sd3_ipadapter_ui(prefix)) + components.update(create_style_ui(prefix)) + components.update(create_embedding_ui(prefix)) components.update(create_conditioning_ui(prefix)) - # components.update(create_vae_override_ui(prefix)) + components.update(create_reference_latent_ui(prefix)) + components.update(create_vae_override_ui(prefix)) components[f'accordion_wrapper_{prefix}'] = accordion_wrapper return components \ No newline at end of file diff --git a/ui/shared/outpaint_ui.py b/ui/shared/outpaint_ui.py index be0e847dc83ddc09bbc80e0b2254bded08cff5bd..3086ad53bf809e7243069204997c59f5fce65fe5 100644 --- a/ui/shared/outpaint_ui.py +++ b/ui/shared/outpaint_ui.py @@ -3,8 +3,10 @@ from core.settings import MODEL_MAP_CHECKPOINT from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES from .ui_components import ( create_lora_settings_ui, - create_embedding_ui, - create_conditioning_ui, create_vae_override_ui, create_api_key_ui, + create_controlnet_ui, create_diffsynth_controlnet_ui, create_ipadapter_ui, create_embedding_ui, + create_conditioning_ui, create_vae_override_ui, + create_model_architecture_filter_ui, create_category_filter_ui, + create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui, create_reference_latent_ui ) @@ -13,12 +15,16 @@ def create_ui(): components = {} with gr.Column(): + components.update(create_model_architecture_filter_ui(prefix)) + with gr.Row(): + components.update(create_category_filter_ui(prefix)) components[f'base_model_{prefix}'] = gr.Dropdown( label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], - scale=3 + scale=3, + allow_custom_value=True ) with gr.Column(scale=1): components[f'run_{prefix}'] = gr.Button("Run Outpaint", variant="primary") @@ -27,44 +33,51 @@ def create_ui(): with gr.Column(scale=1): components[f'input_image_{prefix}'] = gr.Image(type="pil", label="Input Image", height=255) with gr.Column(scale=2): - components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3, placeholder="Describe the content for the expanded areas...") - components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3, value="") + components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3) + components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3) with gr.Row(): with gr.Column(scale=1): with gr.Row(): - components[f'outpaint_left_{prefix}'] = gr.Slider(label="Pad Left", minimum=0, maximum=512, step=64, value=0) - components[f'outpaint_right_{prefix}'] = gr.Slider(label="Pad Right", minimum=0, maximum=512, step=64, value=256) + components[f'left_{prefix}'] = gr.Slider(label="Pad Left", minimum=0, maximum=512, step=64, value=64) + components[f'right_{prefix}'] = gr.Slider(label="Pad Right", minimum=0, maximum=512, step=64, value=64) with gr.Row(): - components[f'outpaint_top_{prefix}'] = gr.Slider(label="Pad Top", minimum=0, maximum=512, step=64, value=0) - components[f'outpaint_bottom_{prefix}'] = gr.Slider(label="Pad Bottom", minimum=0, maximum=512, step=64, value=0) + components[f'top_{prefix}'] = gr.Slider(label="Pad Top", minimum=0, maximum=512, step=64, value=64) + components[f'bottom_{prefix}'] = gr.Slider(label="Pad Bottom", minimum=0, maximum=512, step=64, value=64) + + components[f'feathering_{prefix}'] = gr.Slider(label="Feathering / Grow Mask", minimum=0, maximum=100, step=1, value=10) with gr.Row(): - components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value="euler") - components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value="simple") + components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0]) + components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]) with gr.Row(): - components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=4) - components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=1.0) + components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28) + components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5) with gr.Row(): components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0) components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1) with gr.Row(): - components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional: Set how long to reserve the GPU.") + components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True) + components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True) + components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.") - components[f'clip_skip_{prefix}'] = gr.State(value=1) components[f'width_{prefix}'] = gr.State(value=512) components[f'height_{prefix}'] = gr.State(value=512) with gr.Column(scale=1): - components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=595) + components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=685) - components.update(create_api_key_ui(prefix)) + components.update(create_lora_settings_ui(prefix)) - # components.update(create_diffsynth_controlnet_ui(prefix)) - # components.update(create_controlnet_ui(prefix)) - # components.update(create_embedding_ui(prefix)) - components.update(create_reference_latent_ui(prefix)) + components.update(create_controlnet_ui(prefix)) + components.update(create_diffsynth_controlnet_ui(prefix)) + components.update(create_ipadapter_ui(prefix)) + components.update(create_flux1_ipadapter_ui(prefix)) + components.update(create_sd3_ipadapter_ui(prefix)) + components.update(create_style_ui(prefix)) + components.update(create_embedding_ui(prefix)) components.update(create_conditioning_ui(prefix)) - # components.update(create_vae_override_ui(prefix)) + components.update(create_reference_latent_ui(prefix)) + components.update(create_vae_override_ui(prefix)) return components \ No newline at end of file diff --git a/ui/shared/txt2img_ui.py b/ui/shared/txt2img_ui.py index 926095899932f538b63d8d6c70a48e5f023e746c..d9b1a20b303c15e5a68b398d4958263bfce74010 100644 --- a/ui/shared/txt2img_ui.py +++ b/ui/shared/txt2img_ui.py @@ -2,8 +2,10 @@ import gradio as gr from core.settings import MODEL_MAP_CHECKPOINT from .ui_components import ( create_base_parameter_ui, create_lora_settings_ui, - create_embedding_ui, - create_conditioning_ui, create_vae_override_ui, create_api_key_ui, + create_controlnet_ui, create_diffsynth_controlnet_ui, create_ipadapter_ui, create_embedding_ui, + create_conditioning_ui, create_vae_override_ui, + create_model_architecture_filter_ui, create_category_filter_ui, + create_sd3_ipadapter_ui, create_flux1_ipadapter_ui, create_style_ui, create_reference_latent_ui ) @@ -13,13 +15,22 @@ def create_ui(): components = {} with gr.Column(): + components.update(create_model_architecture_filter_ui(prefix)) + with gr.Row(): - components[f'base_model_{prefix}'] = gr.Dropdown(label="Base Model", choices=list(MODEL_MAP_CHECKPOINT.keys()), value=list(MODEL_MAP_CHECKPOINT.keys())[0], scale=3) + components.update(create_category_filter_ui(prefix)) + components[f'base_model_{prefix}'] = gr.Dropdown( + label="Base Model", + choices=list(MODEL_MAP_CHECKPOINT.keys()), + value=list(MODEL_MAP_CHECKPOINT.keys())[0], + scale=3, + allow_custom_value=True + ) with gr.Column(scale=1): components[f'run_{prefix}'] = gr.Button("Run", variant="primary") - components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3, placeholder="Enter your prompt") - components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3, value="") + components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=3) + components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=3) with gr.Row(): with gr.Column(scale=1): @@ -28,13 +39,17 @@ def create_ui(): with gr.Column(scale=1): components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=2, object_fit="contain", height=627) - components.update(create_api_key_ui(prefix)) + components.update(create_lora_settings_ui(prefix)) - # components.update(create_diffsynth_controlnet_ui(prefix)) - # components.update(create_controlnet_ui(prefix)) - # components.update(create_embedding_ui(prefix)) - components.update(create_reference_latent_ui(prefix)) + components.update(create_controlnet_ui(prefix)) + components.update(create_diffsynth_controlnet_ui(prefix)) + components.update(create_ipadapter_ui(prefix)) + components.update(create_flux1_ipadapter_ui(prefix)) + components.update(create_sd3_ipadapter_ui(prefix)) + components.update(create_embedding_ui(prefix)) + components.update(create_style_ui(prefix)) components.update(create_conditioning_ui(prefix)) - # components.update(create_vae_override_ui(prefix)) + components.update(create_reference_latent_ui(prefix)) + components.update(create_vae_override_ui(prefix)) return components \ No newline at end of file diff --git a/ui/shared/ui_components.py b/ui/shared/ui_components.py index 79a5b98335e6606f77d998e7087064391ef77cbc..96079b832d625eb688967216ce2a278aeec6be55 100644 --- a/ui/shared/ui_components.py +++ b/ui/shared/ui_components.py @@ -2,12 +2,74 @@ import gradio as gr from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES from core.settings import ( MAX_LORAS, LORA_SOURCE_CHOICES, MAX_EMBEDDINGS, MAX_CONDITIONINGS, - MAX_CONTROLNETS, RESOLUTION_MAP, MAX_REFERENCE_LATENTS + MAX_CONTROLNETS, MAX_IPADAPTERS, RESOLUTION_MAP, ARCHITECTURES_CONFIG, + MODEL_MAP_CHECKPOINT, MODEL_TYPE_MAP, FEATURES_CONFIG, ARCH_CATEGORIES_MAP ) import yaml import os from functools import lru_cache +default_model_name = list(MODEL_MAP_CHECKPOINT.keys())[0] if MODEL_MAP_CHECKPOINT else None +default_m_type = MODEL_TYPE_MAP.get(default_model_name, "SDXL") if default_model_name else "SDXL" +default_architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {}) +default_arch_model_type = default_architectures_dict.get(default_m_type, {}).get("model_type", default_m_type.lower().replace(" ", "").replace(".", "")) +default_arch_features = FEATURES_CONFIG.get(default_arch_model_type, FEATURES_CONFIG.get('default', {})) +default_enabled_chains = default_arch_features.get('enabled_chains', []) + + +@lru_cache(maxsize=1) +def get_ipadapter_config_from_yaml(): + try: + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + _IPADAPTER_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml') + with open(_IPADAPTER_LIST_PATH, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + return config + except Exception as e: + print(f"Warning: Could not load ipadapter.yaml for UI components: {e}") + return {} + +def get_ipadapter_presets(arch="SDXL"): + config = get_ipadapter_config_from_yaml() + presets = [] + if config: + std_presets = config.get("IPAdapter_presets", {}).get(arch, []) + face_presets = config.get("IPAdapter_FaceID_presets", {}).get(arch, []) + if std_presets: + presets.extend(std_presets) + if face_presets: + presets.extend(face_presets) + return presets if presets else ["STANDARD (medium strength)"] + +def create_model_architecture_filter_ui(prefix): + components = {} + ordered_architectures = ARCHITECTURES_CONFIG.get("architecture_order", []) + choices = ["ALL"] + ordered_architectures + + components[f'model_arch_{prefix}'] = gr.Radio( + label="Model Architecture", + choices=choices, + value="ALL", + interactive=True, + visible=False + ) + return components + +def create_category_filter_ui(prefix): + valid_cats = list(set(cat for cats in ARCH_CATEGORIES_MAP.values() for cat in cats)) + cat_choices = ["ALL"] + sorted(valid_cats) + + components = {} + components[f'model_cat_{prefix}'] = gr.Dropdown( + label="Filter Models", + choices=cat_choices, + value="ALL", + interactive=True, + scale=1, + allow_custom_value=True + ) + return components + def create_base_parameter_ui(prefix, defaults=None): if defaults is None: defaults = {} @@ -17,50 +79,37 @@ def create_base_parameter_ui(prefix, defaults=None): with gr.Row(): components[f'aspect_ratio_{prefix}'] = gr.Dropdown( label="Aspect Ratio", - choices=list(RESOLUTION_MAP['sdxl'].keys()), + choices=list(RESOLUTION_MAP.get('sdxl', {}).keys()), value="1:1 (Square)", - interactive=True + interactive=True, + allow_custom_value=True ) with gr.Row(): components[f'width_{prefix}'] = gr.Number(label="Width", value=defaults.get('w', 1024), interactive=True) components[f'height_{prefix}'] = gr.Number(label="Height", value=defaults.get('h', 1024), interactive=True) with gr.Row(): - components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value="euler") - components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value="simple") + components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0]) + components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0]) with gr.Row(): - components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=4) - components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=1.0) + components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28) + components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5) with gr.Row(): components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0) components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1) with gr.Row(): - components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60, Max: 120", info="Optional: Set how long to reserve the GPU. Longer jobs may need more time.") - - components[f'clip_skip_{prefix}'] = gr.State(value=1) + components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True) + components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True) + components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.") return components -def create_api_key_ui(prefix: str): - components = {} - with gr.Accordion("API Key Settings", open=False) as api_key_accordion: - components[f'api_key_accordion_{prefix}'] = api_key_accordion - gr.Markdown("💡 **Tip:** Enter API key (optional). An API key is required for resources that need a login to download. The key will be used for all Civitai downloads on this tab. You can also manually upload the corresponding files to avoid API Key leakage caused by potential vulnerabilities.") - with gr.Row(): - components[f'civitai_api_key_{prefix}'] = gr.Textbox( - label="Civitai API Key", - type="password", - placeholder="Enter your Civitai API key here (optional)" - ) - return components - - def create_lora_settings_ui(prefix: str): components = {} lora_rows, lora_sources, lora_ids, lora_scales, lora_uploads = [], [], [], [], [] - with gr.Accordion("LoRA Settings", open=False) as lora_accordion: + with gr.Accordion("LoRA Settings", open=False, visible=('lora' in default_enabled_chains)) as lora_accordion: components[f'lora_accordion_{prefix}'] = lora_accordion gr.Markdown("💡 **Tip:** When downloading from Civitai, please use the **Version ID**, not the Model ID. You can find the Version ID in the URL (e.g., `civitai.com/models/123?modelVersionId=456`) or under the model's download button.") components[f'lora_count_state_{prefix}'] = gr.State(1) @@ -69,7 +118,7 @@ def create_lora_settings_ui(prefix: str): with gr.Row(visible=i==0) as row: source = gr.Dropdown(label=f"LoRA Source {i+1}", choices=LORA_SOURCE_CHOICES, value=LORA_SOURCE_CHOICES[0], scale=1) lora_id = gr.Textbox(label=f"Civitai Version ID / File", placeholder="Civitai Version ID or Filename", scale=2, type="text") - scale = gr.Slider(label=f"Scale", minimum=-2.0, maximum=2.0, step=0.05, value=0.8, scale=1) + scale = gr.Slider(label=f"Scale", minimum=0.0, maximum=2.0, step=0.05, value=0.8, scale=1) upload = gr.UploadButton(label="Upload", file_types=[".safetensors"], scale=1) lora_rows.append(row) @@ -95,11 +144,273 @@ def create_lora_settings_ui(prefix: str): return components +def create_controlnet_ui(prefix: str, max_units=MAX_CONTROLNETS): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("ControlNet Settings", open=False, visible=('controlnet' in default_enabled_chains)) as accordion: + components[key('controlnet_accordion')] = accordion + + cn_rows, images, series, types, strengths, filepaths = [], [], [], [], [], [] + components.update({ + key('controlnet_rows'): cn_rows, + key('controlnet_images'): images, + key('controlnet_series'): series, + key('controlnet_types'): types, + key('controlnet_strengths'): strengths, + key('controlnet_filepaths'): filepaths + }) + + for i in range(max_units): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"Control Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + types.append(gr.Dropdown(label="Type", choices=[], interactive=True, allow_custom_value=True)) + series.append(gr.Dropdown(label="Series", choices=[], interactive=True, allow_custom_value=True)) + strengths.append(gr.Slider(label="Strength", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True)) + filepaths.append(gr.State(None)) + cn_rows.append(row) + + with gr.Row(): + components[key('add_controlnet_button')] = gr.Button("✚ Add ControlNet") + components[key('delete_controlnet_button')] = gr.Button("➖ Delete ControlNet", visible=False) + components[key('controlnet_count_state')] = gr.State(1) + + all_cn_components_flat = [] + for i in range(max_units): + all_cn_components_flat.extend([ + images[i], types[i], series[i], strengths[i], filepaths[i] + ]) + components[key('all_controlnet_components_flat')] = all_cn_components_flat + + return components + +def create_diffsynth_controlnet_ui(prefix: str, max_units=MAX_CONTROLNETS): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("DiffSynth ControlNet Settings", open=False, visible=('controlnet_model_patch' in default_enabled_chains)) as accordion: + components[key('diffsynth_controlnet_accordion')] = accordion + + cn_rows, images, series, types, strengths, filepaths = [], [], [], [], [], [] + components.update({ + key('diffsynth_controlnet_rows'): cn_rows, + key('diffsynth_controlnet_images'): images, + key('diffsynth_controlnet_series'): series, + key('diffsynth_controlnet_types'): types, + key('diffsynth_controlnet_strengths'): strengths, + key('diffsynth_controlnet_filepaths'): filepaths + }) + + for i in range(max_units): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"Control Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + types.append(gr.Dropdown(label="Type", choices=[], interactive=True, allow_custom_value=True)) + series.append(gr.Dropdown(label="Series", choices=[], interactive=True, allow_custom_value=True)) + strengths.append(gr.Slider(label="Strength", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True)) + filepaths.append(gr.State(None)) + cn_rows.append(row) + + with gr.Row(): + components[key('add_diffsynth_controlnet_button')] = gr.Button("✚ Add DiffSynth ControlNet") + components[key('delete_diffsynth_controlnet_button')] = gr.Button("➖ Delete DiffSynth ControlNet", visible=False) + components[key('diffsynth_controlnet_count_state')] = gr.State(1) + + all_cn_components_flat = [] + for i in range(max_units): + all_cn_components_flat.extend([ + images[i], types[i], series[i], strengths[i], filepaths[i] + ]) + components[key('all_diffsynth_controlnet_components_flat')] = all_cn_components_flat + + return components + +def create_ipadapter_ui(prefix: str, max_units=MAX_IPADAPTERS): + components = {} + key = lambda name: f"{name}_{prefix}" + + sdxl_presets = get_ipadapter_presets("SDXL") + default_preset = sdxl_presets[0] if sdxl_presets else None + + with gr.Accordion("IPAdapter Settings", open=False, visible=('ipadapter' in default_enabled_chains)) as accordion: + components[key('ipadapter_accordion')] = accordion + gr.Markdown("Powered by [cubiq/ComfyUI_IPAdapter_plus](https://github.com/cubiq/ComfyUI_IPAdapter_plus).") + + with gr.Row(): + components[key('ipadapter_final_preset')] = gr.Dropdown( + label="Preset (for all images)", + choices=sdxl_presets, + value=default_preset, + interactive=True, + allow_custom_value=True + ) + components[key('ipadapter_embeds_scaling')] = gr.Dropdown( + label="Embeds Scaling", + choices=['V only', 'K+V', 'K+V w/ C penalty', 'K+mean(V) w/ C penalty'], + value='V only', + interactive=True + ) + + with gr.Row(): + components[key('ipadapter_combine_method')] = gr.Dropdown( + label="Combine Method", + choices=["concat", "add", "subtract", "average", "norm average", "max", "min"], + value="concat", + interactive=True + ) + components[key('ipadapter_final_weight')] = gr.Slider(label="Final Weight", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True) + components[key('ipadapter_final_lora_strength')] = gr.Slider(label="Final LoRA Strength", minimum=0.0, maximum=2.0, step=0.05, value=0.6, interactive=True, visible=False) + + gr.Markdown("---") + + ipa_rows, images, weights, lora_strengths = [], [], [], [] + components.update({ + key('ipadapter_rows'): ipa_rows, + key('ipadapter_images'): images, + key('ipadapter_weights'): weights, + key('ipadapter_lora_strengths'): lora_strengths + }) + + for i in range(max_units): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"IPAdapter Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + weights.append(gr.Slider(label="Weight", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True)) + lora_strengths.append(gr.Slider(label="LoRA Strength", minimum=0.0, maximum=2.0, step=0.05, value=0.6, interactive=True, visible=False)) + ipa_rows.append(row) + + with gr.Row(): + components[key('add_ipadapter_button')] = gr.Button("✚ Add IPAdapter") + components[key('delete_ipadapter_button')] = gr.Button("➖ Delete IPAdapter", visible=False) + components[key('ipadapter_count_state')] = gr.State(1) + + all_ipa_components_flat = images + weights + lora_strengths + all_ipa_components_flat += [ + components[key('ipadapter_final_preset')], + components[key('ipadapter_final_weight')], + components[key('ipadapter_final_lora_strength')], + components[key('ipadapter_embeds_scaling')], + components[key('ipadapter_combine_method')], + ] + components[key('all_ipadapter_components_flat')] = all_ipa_components_flat + + return components + +def create_flux1_ipadapter_ui(prefix: str, max_units=MAX_IPADAPTERS): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("IPAdapter Settings (FLUX.1)", open=False, visible=('flux1_ipadapter' in default_enabled_chains)) as accordion: + components[key('flux1_ipadapter_accordion')] = accordion + + ipa_rows, images, weights, start_percents, end_percents = [], [], [], [], [] + components.update({ + key('flux1_ipadapter_rows'): ipa_rows, + key('flux1_ipadapter_images'): images, + key('flux1_ipadapter_weights'): weights, + key('flux1_ipadapter_start_percents'): start_percents, + key('flux1_ipadapter_end_percents'): end_percents, + }) + + for i in range(max_units): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"IPAdapter Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + weights.append(gr.Slider(label="Weight", minimum=0.0, maximum=2.0, step=0.05, value=0.6, interactive=True)) + with gr.Row(): + start_percents.append(gr.Slider(label="Start At", minimum=0.0, maximum=1.0, step=0.01, value=0.0, interactive=True)) + end_percents.append(gr.Slider(label="End At", minimum=0.0, maximum=1.0, step=0.01, value=0.6, interactive=True)) + ipa_rows.append(row) + + with gr.Row(): + components[key('add_flux1_ipadapter_button')] = gr.Button("✚ Add IPAdapter (FLUX)") + components[key('delete_flux1_ipadapter_button')] = gr.Button("➖ Delete IPAdapter (FLUX)", visible=False) + components[key('flux1_ipadapter_count_state')] = gr.State(1) + + all_flux1_ipa_components_flat = images + weights + start_percents + end_percents + components[key('all_flux1_ipadapter_components_flat')] = all_flux1_ipa_components_flat + + return components + +def create_sd3_ipadapter_ui(prefix: str, max_units=MAX_IPADAPTERS): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("IPAdapter Settings (SD3)", open=False, visible=('sd3_ipadapter' in default_enabled_chains)) as accordion: + components[key('sd3_ipadapter_accordion')] = accordion + + ipa_rows, images, weights, start_percents, end_percents = [], [], [], [], [] + components.update({ + key('sd3_ipadapter_rows'): ipa_rows, + key('sd3_ipadapter_images'): images, + key('sd3_ipadapter_weights'): weights, + key('sd3_ipadapter_start_percents'): start_percents, + key('sd3_ipadapter_end_percents'): end_percents, + }) + + for i in range(max_units): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"IPAdapter Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + weights.append(gr.Slider(label="Weight", minimum=0.0, maximum=2.0, step=0.05, value=0.5, interactive=True)) + with gr.Row(): + start_percents.append(gr.Slider(label="Start At", minimum=0.0, maximum=1.0, step=0.01, value=0.0, interactive=True)) + end_percents.append(gr.Slider(label="End At", minimum=0.0, maximum=1.0, step=0.01, value=1.0, interactive=True)) + ipa_rows.append(row) + + with gr.Row(): + components[key('add_sd3_ipadapter_button')] = gr.Button("✚ Add IPAdapter (SD3)") + components[key('delete_sd3_ipadapter_button')] = gr.Button("➖ Delete IPAdapter (SD3)", visible=False) + components[key('sd3_ipadapter_count_state')] = gr.State(1) + + all_sd3_ipa_components_flat = images + weights + start_percents + end_percents + components[key('all_sd3_ipadapter_components_flat')] = all_sd3_ipa_components_flat + + return components + +def create_style_ui(prefix: str): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("Style Settings (FLUX.1)", open=False, visible=('style' in default_enabled_chains)) as accordion: + components[key('style_accordion')] = accordion + + style_rows, images, strengths = [], [], [] + components.update({ + key('style_rows'): style_rows, + key('style_images'): images, + key('style_strengths'): strengths + }) + + for i in range(5): + with gr.Row(visible=(i < 1)) as row: + with gr.Column(scale=1): + images.append(gr.Image(label=f"Style Image {i+1}", type="pil", sources=["upload"], height=256)) + with gr.Column(scale=2): + strengths.append(gr.Slider(label="Strength", minimum=0.0, maximum=2.0, step=0.05, value=1.0, interactive=True)) + style_rows.append(row) + + with gr.Row(): + components[key('add_style_button')] = gr.Button("✚ Add Style (FLUX)") + components[key('delete_style_button')] = gr.Button("➖ Delete Style (FLUX)", visible=False) + components[key('style_count_state')] = gr.State(1) + + all_style_components_flat = images + strengths + components[key('all_style_components_flat')] = all_style_components_flat + + return components + def create_embedding_ui(prefix: str): components = {} key = lambda name: f"{name}_{prefix}" - with gr.Accordion("Embedding Settings", open=False, visible=True) as accordion: + with gr.Accordion("Embedding Settings", open=False, visible=('embedding' in default_enabled_chains)) as accordion: components[key('embedding_accordion')] = accordion gr.Markdown("💡 **Tip:** Embeddings are automatically added to your prompt using `embedding:filename` syntax. When downloading from Civitai, please use the **Version ID**, not the Model ID. You can find the Version ID in the URL (e.g., `civitai.com/models/123?modelVersionId=456`) or under the model's download button. For instance, using the Version ID `456` from the example above would automatically append `embedding:civitai_456` to your positive prompt.") @@ -137,7 +448,7 @@ def create_conditioning_ui(prefix: str): components = {} key = lambda name: f"{name}_{prefix}" - with gr.Accordion("Conditioning Settings", open=False) as accordion: + with gr.Accordion("Conditioning Settings", open=False, visible=('conditioning' in default_enabled_chains)) as accordion: components[key('conditioning_accordion')] = accordion gr.Markdown("💡 **Tip:** Define rectangular areas and assign specific prompts to them. Coordinates (X, Y) start from the top-left corner.") @@ -173,35 +484,6 @@ def create_conditioning_ui(prefix: str): return components -def create_reference_latent_ui(prefix: str): - components = {} - key = lambda name: f"{name}_{prefix}" - - with gr.Accordion("Reference Edit", open=False) as accordion: - components[key('reference_latent_accordion')] = accordion - gr.Markdown("💡 **Tip:** For multimodal models (like FLUX.2), this feature enables powerful editing and combining capabilities. In txt2img mode, adding a single reference image performs an **Image Edit**, while adding multiple images performs an **Image Combine**.") - - ref_rows, ref_images = [], [] - components.update({ - key('reference_latent_rows'): ref_rows, - key('reference_latent_images'): ref_images, - }) - - with gr.Row(): - for i in range(MAX_REFERENCE_LATENTS): - with gr.Column(visible=(i < 1), min_width=160) as row_wrapper: - ref_images.append(gr.Image(type="pil", label=f"Reference {i+1}", sources=["upload"], height=150)) - ref_rows.append(row_wrapper) - - with gr.Row(): - components[key('add_reference_latent_button')] = gr.Button("✚ Add Reference Image") - components[key('delete_reference_latent_button')] = gr.Button("➖ Delete Reference Image", visible=False) - components[key('reference_latent_count_state')] = gr.State(1) - - components[key('all_reference_latent_components_flat')] = ref_images - - return components - def create_vae_override_ui(prefix: str): components = {} key = lambda name: f"{name}_{prefix}" @@ -233,4 +515,33 @@ def create_vae_override_ui(prefix: str): components[key('vae_upload_button')] = upload_btn components[key('vae_file')] = gr.State(None) + return components + +def create_reference_latent_ui(prefix: str, max_units=10): + components = {} + key = lambda name: f"{name}_{prefix}" + + with gr.Accordion("Reference Edit Settings", open=False, visible=('reference_latent' in default_enabled_chains)) as ref_accordion: + components[key('reference_latent_accordion')] = ref_accordion + gr.Markdown("💡 **Tip:** For multimodal models (like FLUX.2 or OmniGen), this feature enables powerful editing and combining capabilities. In txt2img mode, adding a single reference image performs an **Image Edit**, while adding multiple images performs an **Image Combine**.") + + ref_image_groups = [] + ref_image_inputs = [] + with gr.Row(): + for i in range(max_units): + with gr.Column(visible=(i < 1), min_width=160) as img_col: + img_comp = gr.Image(type="pil", label=f"Ref. {i+1}", sources=["upload"], height=150) + ref_image_groups.append(img_col) + ref_image_inputs.append(img_comp) + + components[key('reference_latent_rows')] = ref_image_groups + components[key('reference_latent_images')] = ref_image_inputs + + with gr.Row(): + components[key('add_reference_latent_button')] = gr.Button("✚ Add Reference Image") + components[key('delete_reference_latent_button')] = gr.Button("➖ Delete Reference Image", visible=False) + components[key('reference_latent_count_state')] = gr.State(1) + + components[key('all_reference_latent_components_flat')] = ref_image_inputs + return components \ No newline at end of file diff --git a/utils/app_utils.py b/utils/app_utils.py index e6a7b1e752cc2d733ccd7d339a648527de2dcf0f..462c5bcbda600f5626173e4404e79d6a619f4abc 100644 --- a/utils/app_utils.py +++ b/utils/app_utils.py @@ -11,16 +11,38 @@ from huggingface_hub import hf_hub_download, constants as hf_constants import torch import numpy as np from PIL import Image, ImageChops - +import yaml from core.settings import * DISK_LIMIT_GB = 120 MODELS_ROOT_DIR = "ComfyUI/models" -PREPROCESSOR_MODEL_MAP = None -PREPROCESSOR_PARAMETER_MAP = None - +IPADAPTER_PRESETS = None + +class UniqueKeyLoader(yaml.SafeLoader): + """ + A custom YAML loader that handles duplicate keys by grouping their values into a list. + """ + def construct_mapping(self, node, deep=False): + mapping = [] + for key_node, value_node in node.value: + key = self.construct_object(key_node, deep=deep) + value = self.construct_object(value_node, deep=deep) + mapping.append((key, value)) + + result = {} + for k, v in mapping: + if k in result: + if isinstance(result[k], list): + result[k].append(v) + else: + result[k] = [result[k], v] + else: + result[k] = v + return result + +UniqueKeyLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, UniqueKeyLoader.construct_mapping) def save_uploaded_file_with_hash(file_obj: gr.File, target_dir: str) -> str: if not file_obj: @@ -48,7 +70,6 @@ def save_uploaded_file_with_hash(file_obj: gr.File, target_dir: str) -> str: return hashed_filename - def bytes_to_gb(byte_size: int) -> float: if byte_size is None or byte_size == 0: return 0.0 @@ -116,7 +137,6 @@ def enforce_disk_limit(): except Exception as e: print(f"--- [Storage Manager] An unexpected error occurred: {e} ---") - def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any: try: return obj[index] @@ -151,7 +171,6 @@ def sanitize_filename(filename: str) -> str: sanitized = re.sub(r'[^\w\.\-]', '_', sanitized) return sanitized.lstrip('/\\') - def get_civitai_file_info(version_id: str) -> dict | None: api_url = f"https://civitai.com/api/v1/model-versions/{version_id}" try: @@ -168,7 +187,6 @@ def get_civitai_file_info(version_id: str) -> dict | None: except Exception: return None - def download_file(url: str, save_path: str, api_key: str = None, progress=None, desc: str = "") -> str: enforce_disk_limit() @@ -197,7 +215,6 @@ def download_file(url: str, save_path: str, api_key: str = None, progress=None, os.remove(save_path) return f"Download failed for {os.path.basename(save_path)}: {e}" - def get_lora_path(source: str, id_or_url: str, civitai_key: str, progress) -> tuple[str | None, str]: if not id_or_url or not id_or_url.strip(): return None, "No ID/URL provided." @@ -301,47 +318,44 @@ def get_vae_path(source: str, id_or_url: str, civitai_key: str, progress) -> tup return (local_path, status) if "Successfully" in status else (None, status) -def _ensure_model_downloaded(filename: str, progress=gr.Progress()): - download_info = ALL_FILE_DOWNLOAD_MAP.get(filename) +def _ensure_model_downloaded(display_name: str, progress=gr.Progress()): + if display_name not in ALL_MODEL_MAP: + raise ValueError(f"Model '{display_name}' not found in configuration.") + + model_info = ALL_MODEL_MAP[display_name] + repo_filename = model_info[1] + base_filename = os.path.basename(repo_filename) + + download_info = ALL_FILE_DOWNLOAD_MAP.get(base_filename) if not download_info: - raise gr.Error(f"Model component '{filename}' not found in file_list.yaml. Cannot download.") - - category_to_dir_map = { - "diffusion_models": DIFFUSION_MODELS_DIR, - "text_encoders": TEXT_ENCODERS_DIR, - "vae": VAE_DIR, - "checkpoints": CHECKPOINT_DIR, - "loras": LORA_DIR, - "controlnet": CONTROLNET_DIR, - "model_patches": MODEL_PATCHES_DIR, - "clip_vision": os.path.join(os.path.dirname(LORA_DIR), "clip_vision") - } + raise gr.Error(f"Model '{base_filename}' not found in file_list.yaml. Cannot download.") + + category = download_info.get("category") + dest_dir = CATEGORY_TO_DIR_MAP.get(category) - category = download_info.get('category') - dest_dir = category_to_dir_map.get(category) if not dest_dir: - raise ValueError(f"Unknown model category '{category}' for file '{filename}'.") + raise ValueError(f"Unknown YAML category '{category}' for '{base_filename}'.") - dest_path = os.path.join(dest_dir, filename) + dest_path = os.path.join(dest_dir, base_filename) if os.path.lexists(dest_path): if not os.path.exists(dest_path): print(f"⚠️ Found and removed broken symlink: {dest_path}") os.remove(dest_path) else: - return filename + return base_filename source = download_info.get("source") try: - progress(0, desc=f"Downloading: {filename}") + progress(0, desc=f"Downloading: {base_filename}") if source == "hf": repo_id = download_info.get("repo_id") - hf_filename = download_info.get("repository_file_path", filename) + hf_filename = download_info.get("repository_file_path", base_filename) if not repo_id: - raise ValueError(f"repo_id is missing for HF model '{filename}'") + raise ValueError(f"repo_id is missing for HF model '{base_filename}'") - cached_path = hf_hub_download(repo_id=repo_id, filename=hf_filename) + cached_path = hf_hub_download(repo_id=repo_id, filename=hf_filename, token=os.environ.get("HF_TOKEN")) os.makedirs(dest_dir, exist_ok=True) os.symlink(cached_path, dest_path) print(f"✅ Symlinked '{cached_path}' to '{dest_path}'") @@ -349,98 +363,168 @@ def _ensure_model_downloaded(filename: str, progress=gr.Progress()): elif source == "civitai": model_version_id = download_info.get("model_version_id") if not model_version_id: - raise ValueError(f"model_version_id is missing for Civitai model '{filename}'") + raise ValueError(f"model_version_id is missing for Civitai model '{base_filename}'") file_info = get_civitai_file_info(model_version_id) if not file_info or not file_info.get('downloadUrl'): raise ConnectionError(f"Could not get download URL for Civitai model version ID {model_version_id}") status = download_file( - file_info['downloadUrl'], dest_path, progress=progress, desc=f"Downloading: {filename}" + file_info['downloadUrl'], dest_path, api_key=os.environ.get("CIVITAI_API_KEY", ""), progress=progress, desc=f"Downloading: {base_filename}" ) if "Failed" in status: raise ConnectionError(status) else: - raise NotImplementedError(f"Download source '{source}' is not implemented for '{filename}'") + raise NotImplementedError(f"Download source '{source}' is not implemented for '{base_filename}'") - progress(1.0, desc=f"Downloaded: {filename}") + progress(1.0, desc=f"Downloaded: {base_filename}") except Exception as e: if os.path.lexists(dest_path): try: os.remove(dest_path) except OSError: pass - raise gr.Error(f"Failed to download and link '{filename}': {e}") + raise gr.Error(f"Failed to download and link '{display_name}': {e}") - return filename + return base_filename def ensure_controlnet_model_downloaded(filename: str, progress): if not filename or filename == "None": return - _ensure_model_downloaded(filename, progress) + download_info = ALL_FILE_DOWNLOAD_MAP.get(filename) + if not download_info: + raise gr.Error(f"ControlNet model '{filename}' not found in configuration (file_list.yaml). Cannot download.") + + category = download_info.get("category", "controlnet") + dest_dir = CATEGORY_TO_DIR_MAP.get(category, CONTROLNET_DIR) + dest_path = os.path.join(dest_dir, filename) + + if os.path.lexists(dest_path): + if not os.path.exists(dest_path): + print(f"⚠️ Found and removed broken symlink: {dest_path}") + os.remove(dest_path) + else: + return + + source = download_info.get("source") + + try: + if source == "hf": + repo_id = download_info.get("repo_id") + repo_filename = download_info.get("repository_file_path", filename) + if not repo_id: + raise ValueError("repo_id is missing for Hugging Face download.") + + progress(0, desc=f"Downloading CN: {filename}") + cached_path = hf_hub_download(repo_id=repo_id, filename=repo_filename, token=os.environ.get("HF_TOKEN")) + os.makedirs(dest_dir, exist_ok=True) + os.symlink(cached_path, dest_path) + print(f"✅ Symlinked ControlNet '{cached_path}' to '{dest_path}'") + progress(1.0, desc=f"Downloaded CN: {filename}") + + elif source == "civitai": + model_version_id = download_info.get("model_version_id") + if not model_version_id: + raise ValueError("model_version_id is missing for Civitai download.") + + file_info = get_civitai_file_info(model_version_id) + if not file_info or not file_info.get('downloadUrl'): + raise ConnectionError(f"Could not get download URL for Civitai model version ID {model_version_id}") + + status = download_file( + file_info['downloadUrl'], + dest_path, + api_key=os.environ.get("CIVITAI_API_KEY", ""), + progress=progress, + desc=f"Downloading CN: {filename}" + ) + if "Failed" in status: + raise ConnectionError(status) + else: + raise NotImplementedError(f"Download source '{source}' is not implemented for ControlNets.") + + except Exception as e: + if os.path.lexists(dest_path): + try: + os.remove(dest_path) + except OSError: + pass + raise gr.Error(f"Failed to download ControlNet model '{filename}': {e}") + +def load_ipadapter_presets(): + global IPADAPTER_PRESETS + if IPADAPTER_PRESETS is not None: + return + + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + _IPADAPTER_MODELS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter_models.yaml') + + try: + with open(_IPADAPTER_MODELS_PATH, 'r', encoding='utf-8') as f: + presets_list = yaml.load(f, Loader=UniqueKeyLoader) + + IPADAPTER_PRESETS = {item['preset_name']: item for item in presets_list} + print("✅ IPAdapter presets loaded successfully.") + except Exception as e: + print(f"❌ FATAL: Could not load or parse ipadapter_models.yaml. IPAdapter will not work. Error: {e}") + IPADAPTER_PRESETS = {} + +def ensure_ipadapter_models_downloaded(preset_name: str, progress): + if not preset_name: + return + + if IPADAPTER_PRESETS is None: + raise RuntimeError("IPAdapter presets have not been loaded. `load_ipadapter_presets` must be called on startup.") + + preset_info = IPADAPTER_PRESETS.get(preset_name) + if not preset_info: + print(f"⚠️ Warning: IPAdapter preset '{preset_name}' not found in configuration. Skipping download.") + return + + model_files_to_check = [] + + def add_files(value, type_name): + if not value: return + if isinstance(value, list): + for v in value: + model_files_to_check.append((v, type_name)) + else: + model_files_to_check.append((value, type_name)) + + add_files(preset_info.get('clip_vision'), 'CLIP_VISION') + add_files(preset_info.get('ipadapter'), 'IPADAPTER') + add_files(preset_info.get('loras'), 'LORA') + + for filename, model_type in model_files_to_check: + if not filename: + continue + + temp_display_name = f"ipadapter_asset_{filename}" + + if temp_display_name not in ALL_MODEL_MAP: + ALL_MODEL_MAP[temp_display_name] = (None, filename, model_type, None, None) -def build_preprocessor_model_map(): - global PREPROCESSOR_MODEL_MAP - if PREPROCESSOR_MODEL_MAP is not None: return PREPROCESSOR_MODEL_MAP - print("--- Building ControlNet Preprocessor model map ---") - manual_map = { - "dwpose": [("yzd-v/DWPose", "yolox_l.onnx"), ("yzd-v/DWPose", "dw-ll_ucoco_384.onnx"), ("hr16/UnJIT-DWPose", "dw-ll_ucoco.onnx"), ("hr16/DWPose-TorchScript-BatchSize5", "dw-ll_ucoco_384_bs5.torchscript.pt"), ("hr16/DWPose-TorchScript-BatchSize5", "rtmpose-m_ap10k_256_bs5.torchscript.pt"), ("hr16/yolo-nas-fp16", "yolo_nas_l_fp16.onnx"), ("hr16/yolo-nas-fp16", "yolo_nas_m_fp16.onnx"), ("hr16/yolo-nas-fp16", "yolo_nas_s_fp16.onnx")], - "densepose": [("LayerNorm/DensePose-TorchScript-with-hint-image", "densepose_r50_fpn_dl.torchscript"), ("LayerNorm/DensePose-TorchScript-with-hint-image", "densepose_r101_fpn_dl.torchscript")] - } - temp_map = {} - from nodes import NODE_DISPLAY_NAME_MAPPINGS - wrappers_dir = Path("./custom_nodes/comfyui_controlnet_aux/node_wrappers/") - if not wrappers_dir.exists(): - print("⚠️ ControlNet AUX wrappers directory not found. Cannot build model map.") - PREPROCESSOR_MODEL_MAP = {}; return PREPROCESSOR_MODEL_MAP - for wrapper_file in wrappers_dir.glob("*.py"): - if wrapper_file.name == "__init__.py": continue - with open(wrapper_file, 'r', encoding='utf-8') as f: - content = f.read() - display_name_matches = re.findall(r'NODE_DISPLAY_NAME_MAPPINGS\s*=\s*{(?:.|\n)*?["\'](.*?)["\']\s*:\s*["\'](.*?)["\']', content) - for _, display_name in display_name_matches: - if display_name not in temp_map: temp_map[display_name] = [] - manual_key = wrapper_file.stem - if manual_key in manual_map: temp_map[display_name].extend(manual_map[manual_key]) - matches = re.findall(r"from_pretrained\s*\(\s*(?:filename=)?\s*f?[\"']([^\"']+)[\"']", content) - for model_filename in matches: - repo_id = "lllyasviel/Annotators" - if "depth_anything" in model_filename and "v2" in model_filename: repo_id = "LiheYoung/Depth-Anything-V2" - elif "depth_anything" in model_filename: repo_id = "LiheYoung/Depth-Anything" - elif "diffusion_edge" in model_filename: repo_id = "hr16/Diffusion-Edge" - temp_map[display_name].append((repo_id, model_filename)) - final_map = {name: sorted(list(set(models))) for name, models in temp_map.items() if models} - PREPROCESSOR_MODEL_MAP = final_map - print("✅ ControlNet Preprocessor model map built."); return PREPROCESSOR_MODEL_MAP - -def build_preprocessor_parameter_map(): - global PREPROCESSOR_PARAMETER_MAP - if PREPROCESSOR_PARAMETER_MAP is not None: return - print("--- Building ControlNet Preprocessor parameter map ---") - param_map = {} - from nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS - for class_name, node_class in NODE_CLASS_MAPPINGS.items(): - if not hasattr(node_class, "INPUT_TYPES"): continue - if hasattr(node_class, '__module__') and 'comfyui_controlnet_aux.node_wrappers' not in node_class.__module__: continue - display_name = NODE_DISPLAY_NAME_MAPPINGS.get(class_name) - if not display_name: continue try: - input_types = node_class.INPUT_TYPES() - all_inputs = {**input_types.get('required', {}), **input_types.get('optional', {})} - params = [] - for name, details in all_inputs.items(): - if name in ['image', 'resolution', 'pose_kps']: continue - if not isinstance(details, (list, tuple)) or not details: continue - param_type = details[0] - param_config = details[1] if len(details) > 1 and isinstance(details[1], dict) else {} - param_info = {"name": name, "type": param_type, "config": param_config} - params.append(param_info) - if params: param_map[display_name] = params + _ensure_model_downloaded(temp_display_name, progress) except Exception as e: - print(f"⚠️ Could not parse parameters for {display_name}: {e}") - PREPROCESSOR_PARAMETER_MAP = param_map - print("✅ ControlNet Preprocessor parameter map built.") + print(f"❌ Error ensuring download for IPAdapter asset '{filename}': {e}") + + +def ensure_sd3_ipadapter_models_downloaded(progress): + _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + yaml_path = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter_sd3_models.yaml') + try: + with open(yaml_path, 'r', encoding='utf-8') as f: + sd3_models = yaml.safe_load(f) + if sd3_models: + if 'ipadapter' in sd3_models: + _ensure_model_downloaded(sd3_models['ipadapter'], progress) + if 'clip_vision' in sd3_models: + _ensure_model_downloaded(sd3_models['clip_vision'], progress) + except Exception as e: + print(f"Warning: Failed to load or download sd3 ipadapter models: {e}") + def print_welcome_message(): author_name = "RioShiina" @@ -459,4 +543,24 @@ def print_welcome_message(): f"{border}\n" ) - print(message) \ No newline at end of file + print(message) + +def get_model_generation_defaults(model_display_name: str, model_type: str, defaults_config: dict): + final_defaults = { + 'steps': 25, 'cfg': 7.0, 'sampler_name': 'euler', 'scheduler': 'simple', + 'positive_prompt': '', 'negative_prompt': '' + } + + if 'Default' in defaults_config: + final_defaults.update(defaults_config['Default']) + + model_type_key = next((key for key in defaults_config if key.lower().replace(" ", "-").replace(".", "") == model_type.lower()), None) + if model_type_key: + model_type_config = defaults_config[model_type_key] + if '_defaults' in model_type_config: + final_defaults.update(model_type_config['_defaults']) + + if model_display_name in model_type_config: + final_defaults.update(model_type_config[model_display_name]) + + return final_defaults \ No newline at end of file diff --git a/yaml/constants.yaml b/yaml/constants.yaml index 5e758c19eec38c2afde1016127a7733845fb270f..91e988ac66bece15f1265a47e2e11eddff9320b9 100644 --- a/yaml/constants.yaml +++ b/yaml/constants.yaml @@ -1,11 +1,116 @@ MAX_LORAS: 5 MAX_CONTROLNETS: 5 +MAX_IPADAPTERS: 5 MAX_EMBEDDINGS: 5 MAX_CONDITIONINGS: 10 MAX_REFERENCE_LATENTS: 10 LORA_SOURCE_CHOICES: ["Civitai", "File"] RESOLUTION_MAP: + ernie-image: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + flux2: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + flux2-kv: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + qwen-image: + "1:1 (Square)": [1328, 1328] + "16:9 (Landscape)": [1664, 928] + "9:16 (Portrait)": [928, 1664] + "4:3 (Classic)": [1472, 1104] + "3:4 (Classic Portrait)": [1104, 1472] + "3:2 (Photography)": [1536, 1024] + "2:3 (Photography Portrait)": [1024, 1536] + longcat-image: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + anima: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + newbie-image: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + omnigen2: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + lumina: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + ovis-image: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + flux1: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + hidream: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + sd35: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] sdxl: "1:1 (Square)": [1024, 1024] "16:9 (Landscape)": [1344, 768] @@ -13,4 +118,36 @@ RESOLUTION_MAP: "4:3 (Classic)": [1152, 896] "3:4 (Classic Portrait)": [896, 1152] "3:2 (Photography)": [1216, 832] - "2:3 (Photography Portrait)": [832, 1216] \ No newline at end of file + "2:3 (Photography Portrait)": [832, 1216] + sd15: + "1:1 (Square)": [512, 512] + "16:9 (Landscape)": [896, 512] + "9:16 (Portrait)": [512, 896] + "4:3 (Classic Landscape)": [683, 512] + "3:4 (Classic Portrait)": [512, 683] + "3:2 (Landscape)": [768, 512] + "2:3 (Portrait)": [512, 768] + chroma1-radiance: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + chroma1: + "1:1 (Square)": [1024, 1024] + "16:9 (Landscape)": [1344, 768] + "9:16 (Portrait)": [768, 1344] + "4:3 (Classic)": [1152, 896] + "3:4 (Classic Portrait)": [896, 1152] + "3:2 (Photography)": [1216, 832] + "2:3 (Photography Portrait)": [832, 1216] + hunyuanimage: + "1:1 (Square)": [2048, 2048] + "16:9 (Landscape)": [2728, 1536] + "9:16 (Portrait)": [1536, 2728] + "4:3 (Classic)": [2368, 1776] + "3:4 (Classic Portrait)": [1776, 2368] + "3:2 (Photography)": [2504, 1672] + "2:3 (Photography Portrait)": [1672, 2504] \ No newline at end of file diff --git a/yaml/controlnet_models.yaml b/yaml/controlnet_models.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b3f668b7b52dc9b29623855c938b8939b9c5e94e --- /dev/null +++ b/yaml/controlnet_models.yaml @@ -0,0 +1,177 @@ +ControlNet: + Qwen-Image: + - Filepath: "Qwen-Image-InstantX-ControlNet-Union.safetensors" + Series: "InstantX Union" + Type: ["Canny", "Soft Edge", "Depth", "Pose"] + FLUX.1: + - Filepath: "FLUX.1-dev-ControlNet-Union-Pro-2.0.safetensors" + Series: "Shakker Labs Union Pro" + Type: ["Canny", "Tile", "Depth", "Blur", "Pose", "Gray", "Low Quality"] + - Filepath: "flux-canny-controlnet-v3.safetensors" + Series: "XLabs-AI" + Type: ["Canny"] + - Filepath: "flux-depth-controlnet-v3.safetensors" + Series: "XLabs-AI" + Type: ["Depth (Midas)"] + - Filepath: "flux-hed-controlnet-v3.safetensors" + Series: "XLabs-AI" + Type: ["HED"] + SD3.5: + - Filepath: "sd3.5_large_controlnet_blur.safetensors" + Series: "[Large] StabilityAI" + Type: ["Blur"] + - Filepath: "sd3.5_large_controlnet_canny.safetensors" + Series: "[Large] StabilityAI" + Type: ["Canny"] + - Filepath: "sd3.5_large_controlnet_depth.safetensors" + Series: "[Large] StabilityAI" + Type: ["Depth"] + SDXL: + - Filepath: "controlnet-union-sdxl-1.0_promax.safetensors" + Series: "xinsir Union" + Type: ["Tile Deblur", "Tile variation", "Tile Super Resolution", "Image Inpainting", "Image Outpainting", "OpenPose", "Depth", "Canny", "Lineart", "Anime Lineart", "Mlsd", "Scribble", "Hed", "Pidi(Softedge)", "Teed", "Segment", "Normal"] + - Filepath: "controlnet-tile-sdxl-1.0.safetensors" + Series: "xinsir" + Type: ["Tile"] + - Filepath: "controlnet-canny-sdxl-1.0_V2.safetensors" + Series: "xinsir" + Type: ["Canny"] + - Filepath: "controlnet-openpose-sdxl-1.0.safetensors" + Series: "xinsir" + Type: ["OpenPose"] + - Filepath: "controlnet-openpose-sdxl-1.0.safetensors" + Series: "xinsir" + Type: ["OpenPose(Twins)"] + - Filepath: "controlnet-depth-sdxl-1.0" + Series: "xinsir" + Type: ["Depth"] + - Filepath: "controlnet-scribble-sdxl-1.0.safetensors" + Series: "xinsir" + Type: ["Scribble"] + - Filepath: "anime-painter.safetensors" + Series: "xinsir" + Type: ["Anime Painter"] + # SDXL-NoobAI + - Filepath: "noob_sdxl_controlnet_canny.fp16.safetensors" + Series: "NoobAI" + Type: ["Canny"] + - Filepath: "noob_sdxl_controlnet_depth.fp16.safetensors" + Series: "NoobAI" + Type: ["Depth"] + - Filepath: "noob-sdxl-controlnet-lineart_anime.fp16.safetensors" + Series: "NoobAI" + Type: ["Anime Lineart"] + - Filepath: "noob-sdxl-controlnet-lineart_realistic.fp16.safetensors" + Series: "NoobAI" + Type: ["Realistic Lineart"] + - Filepath: "noob-sdxl-controlnet-manga_line.fp16.safetensors" + Series: "NoobAI" + Type: ["Manga Lineart"] + - Filepath: "noob-sdxl-controlnet-normal.fp16.safetensors" + Series: "NoobAI" + Type: ["Normal"] + - Filepath: "noob-sdxl-controlnet-softedge_hed.fp16.safetensors" + Series: "NoobAI" + Type: ["SoftEdge (HED)"] + - Filepath: "noob-sdxl-controlnet-tile.fp16.safetensors" + Series: "NoobAI" + Type: ["Tile"] + - Filepath: "NoobAI_Inpainting_ControlNet.safetensors" + Series: "NoobAI" + Type: ["Inpainting"] + - Filepath: "noob_openpose_pre.safetensors" + Series: "NoobAI" + Type: ["OpenPose"] + - Filepath: "noobaiXLControlnet_epsDepthMidasV11.safetensors" + Series: "NoobAI" + Type: ["Depth (Midas)"] + - Filepath: "noobaiXLControlnet_epsNormalMidas.safetensors" + Series: "NoobAI" + Type: ["Normal (Midas)"] + - Filepath: "noobaiXLControlnet_epsScribbleHed.safetensors" + Series: "NoobAI" + Type: ["Scribble (HED)"] + - Filepath: "noobaiXLControlnet_epsScribblePidinet.safetensors" + Series: "NoobAI" + Type: ["Scribble (PiDiNet)"] + - Filepath: "noobaiXLControlnet_epsDepthMidas.safetensors" + Series: "NoobAI" + Type: ["Depth (Midas)"] + - Filepath: "noobaiXLControlnet_openposeModel.safetensors" + Series: "NoobAI" + Type: ["OpenPose"] + # SDXL - Illustrious-XL-v0.1 + - Filepath: "illustriousXLv0.1_Canny_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["Canny"] + - Filepath: "illustriousXLv0.1_Lineart_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["Lineart"] + - Filepath: "illustriousXLv0.1_Softedge_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["SoftEdge"] + - Filepath: "illustriousXLv0.1_Tile_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["Tile"] + - Filepath: "illustriousXLv0.1_depth_midas_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["Depth (Midas)"] + - Filepath: "illustriousXLv0.1_inpainting_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv0.1_controlnet" + Type: ["Inpainting"] + # SDXL - Illustrious-XL-v1.1 + - Filepath: "illustriousXLv1.1_canny_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv1.1_controlnet" + Type: ["Canny"] + - Filepath: "illustriousXLv1.1_depth_midas_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv1.1_controlnet" + Type: ["Depth (Midas)"] + - Filepath: "illustriousXLv1.1_inpainting_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv1.1_controlnet" + Type: ["Inpainting"] + - Filepath: "illustriousXLv1.1_tile_fp16.safetensors" + Series: "MIC-Lab/illustriousXLv1.1_controlnet" + Type: ["Tile"] + SD1.5: + - Filepath: "control_v11p_sd15_canny_fp16.safetensors" + Series: "Standard" + Type: ["Canny"] + - Filepath: "control_v11f1p_sd15_depth_fp16.safetensors" + Series: "Standard" + Type: ["Depth"] + - Filepath: "control_v11p_sd15_openpose_fp16.safetensors" + Series: "Standard" + Type: ["OpenPose"] + - Filepath: "control_v11p_sd15_lineart_fp16.safetensors" + Series: "Standard" + Type: ["Lineart"] + - Filepath: "control_v11p_sd15_softedge_fp16.safetensors" + Series: "Standard" + Type: ["SoftEdge"] + - Filepath: "control_v11p_sd15_scribble_fp16.safetensors" + Series: "Standard" + Type: ["Scribble"] + - Filepath: "control_v11p_sd15_seg_fp16.safetensors" + Series: "Standard" + Type: ["Segmentation"] + - Filepath: "control_v11p_sd15_normalbae_fp16.safetensors" + Series: "Standard" + Type: ["Normal BAE"] + - Filepath: "control_v11p_sd15_mlsd_fp16.safetensors" + Series: "Standard" + Type: ["MLSD"] + - Filepath: "control_v11p_sd15_inpaint_fp16.safetensors" + Series: "Standard" + Type: ["Inpaint"] + - Filepath: "control_v11f1e_sd15_tile_fp16.safetensors" + Series: "Standard" + Type: ["Tile"] + - Filepath: "control_v11e_sd15_shuffle_fp16.safetensors" + Series: "Standard" + Type: ["Shuffle"] + - Filepath: "control_v11e_sd15_ip2p_fp16.safetensors" + Series: "Standard" + Type: ["Instruct P2P"] + - Filepath: "control_v11p_sd15s2_lineart_anime_fp16.safetensors" + Series: "Standard" + Type: ["Anime Lineart"] \ No newline at end of file diff --git a/yaml/diffsynth_controlnet_models.yaml b/yaml/diffsynth_controlnet_models.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f8e4b06a57182748fdc067709eef1e1d2b7c8121 --- /dev/null +++ b/yaml/diffsynth_controlnet_models.yaml @@ -0,0 +1,8 @@ +DiffSynth_ControlNet: + Z-Image: + - Filepath: "Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors" + Series: "alibaba-pai Controlnet Union 2.1 8steps" + Type: ["Pose", "Canny", "HED", "Depth", "MLSD"] + - Filepath: "Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors" + Series: "alibaba-pai Controlnet Union 2.1 8steps" + Type: ["Tile"] \ No newline at end of file diff --git a/yaml/file_list.yaml b/yaml/file_list.yaml index 4338a1f503d14ae83565896d71708739e485fb3d..b861d1f9c3ca6f47982521843bdf1190c523b663 100644 --- a/yaml/file_list.yaml +++ b/yaml/file_list.yaml @@ -1,5 +1,313 @@ -file: +file: + checkpoints: + # Lumina + - filename: "lumina_2.safetensors" + source: "hf" + repo_id: "Comfy-Org/Lumina_Image_2.0_Repackaged" + repository_file_path: "all_in_one/lumina_2.safetensors" + # SD3.5 + - filename: "sd3.5_large_fp8_scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/stable-diffusion-3.5-fp8" + repository_file_path: "sd3.5_large_fp8_scaled.safetensors" + - filename: "sd3.5_medium_incl_clips_t5xxlfp8scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/stable-diffusion-3.5-fp8" + repository_file_path: "sd3.5_medium_incl_clips_t5xxlfp8scaled.safetensors" + # SDXL-NoobAI + - filename: "NoobAI-XL-Vpred-v1.0.safetensors" + source: hf + repo_id: "Laxhar/noobai-XL-Vpred-1.0" + repository_file_path: "NoobAI-XL-Vpred-v1.0.safetensors" + - filename: "NoobAI-XL-v1.1.safetensors" + source: hf + repo_id: "Laxhar/noobai-XL-1.1" + repository_file_path: "NoobAI-XL-v1.1.safetensors" + - filename: "noob_v_pencil-XL-v3.0.0.safetensors" + source: hf + repo_id: "bluepen5805/noob_v_pencil-XL" + repository_file_path: "noob_v_pencil-XL-v3.0.0.safetensors" + - filename: "Hikari_Noob_v-pred_1.2.4.safetensors" + source: hf + repo_id: "RedRayz/hikari_noob_v-pred_1.2.4" + repository_file_path: "Hikari_Noob_v-pred_1.2.4.safetensors" + - filename: "ChenkinNoob-XL-V0.5.safetensors" + source: hf + repo_id: "ChenkinNoob/ChenkinNoob-XL-V0.5" + repository_file_path: "ChenkinNoob-XL-V0.5.safetensors" + # SDXL-Illustrious + - filename: "waiIllustriousSDXL_v170.safetensors" + source: hf + repo_id: "zhenshipo/waiIllustriousSDXL_v170" + repository_file_path: "waiIllustriousSDXL_v170.safetensors" + - filename: "mellow_pencil-XL-v1.0.0.safetensors" + source: hf + repo_id: "bluepen5805/mellow_pencil-XL" + repository_file_path: "mellow_pencil-XL-v1.0.0.safetensors" + - filename: "illustrious_pencil-XL-v5.0.0.safetensors" + source: hf + repo_id: "bluepen5805/illustrious_pencil-XL" + repository_file_path: "illustrious_pencil-XL-v5.0.0.safetensors" + - filename: "hassakuXLIllustrious_v34.safetensors" + source: hf + repo_id: "oldhag88/hassakuXLIllustrious_v34.safetensors" + repository_file_path: "hassakuXLIllustrious_v34.safetensors" + - filename: "novaAnimeXL_ilV160.safetensors" + source: hf + repo_id: "Yevrey921/novaAnimeXL_ilV160" + repository_file_path: "novaAnimeXL_ilV160.safetensors" + - filename: "Illustrious-XL-v2.0.safetensors" + source: hf + repo_id: "OnomaAIResearch/Illustrious-XL-v2.0" + - filename: "Illustrious-XL-v2.0.safetensors" + source: hf + repo_id: "OnomaAIResearch/Illustrious-XL-v2.0" + repository_file_path: "Illustrious-XL-v2.0.safetensors" + - filename: "Illustrious-XL-v1.1.safetensors" + source: hf + repo_id: "OnomaAIResearch/Illustrious-XL-v1.1" + repository_file_path: "Illustrious-XL-v1.1.safetensors" + - filename: "Illustrious-XL-v1.0.safetensors" + source: hf + repo_id: "OnomaAIResearch/Illustrious-XL-v1.0" + repository_file_path: "Illustrious-XL-v1.0.safetensors" + - filename: "illustriousXL_v01.safetensors" + source: hf + repo_id: "AiAF/Illustrious-XL-v0.1.safetensors" + repository_file_path: "illustriousXL_v01.safetensors" + # SDXL-Animate + - filename: "animagine-xl-4.0.safetensors" + source: hf + repo_id: "cagliostrolab/animagine-xl-4.0" + repository_file_path: "animagine-xl-4.0.safetensors" + - filename: "animagine-xl-3.1.safetensors" + source: hf + repo_id: "cagliostrolab/animagine-xl-3.1" + repository_file_path: "animagine-xl-3.1.safetensors" + - filename: "4nima_pencil-XL-v1.0.1.safetensors" + source: hf + repo_id: "bluepen5805/4nima_pencil-XL" + repository_file_path: "4nima_pencil-XL-v1.0.1.safetensors" + - filename: "anima_pencil-XL-v5.0.0.safetensors" + source: hf + repo_id: "bluepen5805/anima_pencil-XL" + repository_file_path: "anima_pencil-XL-v5.0.0.safetensors" + - filename: "blue_pencil-XL-v7.0.0.safetensors" + source: hf + repo_id: "bluepen5805/blue_pencil-XL" + repository_file_path: "blue_pencil-XL-v7.0.0.safetensors" + # SDXL-Pony + - filename: "ponyDiffusionV6XL_v6StartWithThisOne.safetensors" + source: hf + repo_id: "LyliaEngine/Pony_Diffusion_V6_XL" + repository_file_path: "ponyDiffusionV6XL_v6StartWithThisOne.safetensors" + - filename: "pony_pencil-XL-v2.0.0.safetensors" + source: hf + repo_id: "bluepen5805/pony_pencil-XL" + repository_file_path: "pony_pencil-XL-v2.0.0.safetensors" + - filename: "CyberRealisticPony_V14.0.safetensors" + source: hf + repo_id: "cyberdelia/CyberRealisticPony" + repository_file_path: "CyberRealisticPony_V14.0.safetensors" + # SDXL-Base + - filename: "sd_xl_base_1.0.safetensors" + source: "hf" + repo_id: "stabilityai/stable-diffusion-xl-base-1.0" + repository_file_path: "sd_xl_base_1.0.safetensors" + # SD1.5 + - filename: "v1-5-pruned-emaonly.safetensors" + source: "hf" + repo_id: "stable-diffusion-v1-5/stable-diffusion-v1-5" + repository_file_path: "v1-5-pruned-emaonly.safetensors" + clip_vision: + # style_injector + - filename: "sigclip_vision_patch14_384.safetensors" + source: "hf" + repo_id: "Comfy-Org/sigclip_vision_384" + repository_file_path: "sigclip_vision_patch14_384.safetensors" + # IPAdapter + - filename: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/image_encoder/model.safetensors" + - filename: "CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "sdxl_models/image_encoder/model.safetensors" + # IPAdapter-SD3 + - filename: "sigclip_vision_patch14_384.safetensors" + source: "hf" + repo_id: "Comfy-Org/sigclip_vision_384" + repository_file_path: "sigclip_vision_patch14_384.safetensors" + controlnet: + # SD3.5 + - filename: "sd3.5_large_controlnet_blur.safetensors" + source: "hf" + repo_id: "stabilityai/stable-diffusion-3.5-controlnets" + repository_file_path: "sd3.5_large_controlnet_blur.safetensors" + - filename: "sd3.5_large_controlnet_canny.safetensors" + source: "hf" + repo_id: "stabilityai/stable-diffusion-3.5-controlnets" + repository_file_path: "sd3.5_large_controlnet_canny.safetensors" + - filename: "sd3.5_large_controlnet_depth.safetensors" + source: "hf" + repo_id: "stabilityai/stable-diffusion-3.5-controlnets" + repository_file_path: "sd3.5_large_controlnet_depth.safetensors" + # Qwen-Image + - filename: "Qwen-Image-InstantX-ControlNet-Union.safetensors" + source: "hf" + repo_id: "InstantX/Qwen-Image-ControlNet-Union" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "Qwen-Image-InstantX-ControlNet-Inpainting.safetensors" + source: "hf" + repo_id: "InstantX/Qwen-Image-ControlNet-Inpainting" + repository_file_path: "diffusion_pytorch_model.safetensors" + # FLUX.1 + - filename: "FLUX.1-dev-ControlNet-Union-Pro-2.0.safetensors" + source: "hf" + repo_id: "Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "flux-canny-controlnet-v3.safetensors" + source: "hf" + repo_id: "XLabs-AI/flux-controlnet-collections" + repository_file_path: "flux-canny-controlnet-v3.safetensors" + - filename: "flux-depth-controlnet-v3.safetensors" + source: "hf" + repo_id: "XLabs-AI/flux-controlnet-collections" + repository_file_path: "flux-depth-controlnet-v3.safetensors" + - filename: "flux-hed-controlnet-v3.safetensors" + source: "hf" + repo_id: "XLabs-AI/flux-controlnet-collections" + repository_file_path: "flux-hed-controlnet-v3.safetensors" + # SDXL + - filename: "controlnet-union-sdxl-1.0_promax.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-union-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model_promax.safetensors" + - filename: "controlnet-tile-sdxl-1.0.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-tile-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "controlnet-canny-sdxl-1.0_V2.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-canny-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model_V2.safetensors" + - filename: "controlnet-openpose-sdxl-1.0.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-openpose-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "controlnet-depth-sdxl-1.0.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-depth-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "controlnet-scribble-sdxl-1.0.safetensors" + source: "hf" + repo_id: "xinsir/controlnet-scribble-sdxl-1.0" + repository_file_path: "diffusion_pytorch_model.safetensors" + - filename: "anime-painter.safetensors" + source: "hf" + repo_id: "xinsir/anime-painter" + repository_file_path: "diffusion_pytorch_model.safetensors" + # SD1.5 + - filename: "control_v11e_sd15_ip2p_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11e_sd15_ip2p_fp16.safetensors" + - filename: "control_v11e_sd15_shuffle_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11e_sd15_shuffle_fp16.safetensors" + - filename: "control_v11f1e_sd15_tile_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11f1e_sd15_tile_fp16.safetensors" + - filename: "control_v11f1p_sd15_depth_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11f1p_sd15_depth_fp16.safetensors" + - filename: "control_v11p_sd15_canny_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_canny_fp16.safetensors" + - filename: "control_v11p_sd15_inpaint_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_inpaint_fp16.safetensors" + - filename: "control_v11p_sd15_lineart_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_lineart_fp16.safetensors" + - filename: "control_v11p_sd15_mlsd_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_mlsd_fp16.safetensors" + - filename: "control_v11p_sd15_normalbae_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_normalbae_fp16.safetensors" + - filename: "control_v11p_sd15_openpose_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_openpose_fp16.safetensors" + - filename: "control_v11p_sd15_scribble_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_scribble_fp16.safetensors" + - filename: "control_v11p_sd15_seg_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_seg_fp16.safetensors" + - filename: "control_v11p_sd15_softedge_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15_softedge_fp16.safetensors" + - filename: "control_v11p_sd15s2_lineart_anime_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11p_sd15s2_lineart_anime_fp16.safetensors" + - filename: "control_v11u_sd15_tile_fp16.safetensors" + source: "hf" + repo_id: "comfyanonymous/ControlNet-v1-1_fp16_safetensors" + repository_file_path: "control_v11u_sd15_tile_fp16.safetensors" diffusion_models: + # FLUX.2-klein-9B + - filename: "flux-2-klein-9b-fp8.safetensors" + source: "hf" + repo_id: "black-forest-labs/FLUX.2-klein-9b-fp8" + repository_file_path: "flux-2-klein-9b-fp8.safetensors" + # FLUX.2-klein-base-9B + - filename: "flux-2-klein-base-9b-fp8.safetensors" + source: "hf" + repo_id: "black-forest-labs/FLUX.2-klein-base-9b-fp8" + repository_file_path: "flux-2-klein-base-9b-fp8.safetensors" + # Anima + - filename: "anima-preview3-base.safetensors" + source: "hf" + repo_id: "circlestone-labs/Anima" + repository_file_path: "split_files/diffusion_models/anima-preview3-base.safetensors" + - filename: "AnimaYume_tuned_v04.safetensors" + source: "hf" + repo_id: "duongve/AnimaYume" + repository_file_path: "split_files/diffusion_models/AnimaYume_tuned_v04.safetensors" + # NewBie-Image + - filename: "NewBie-Image-Exp0.1-bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/NewBie-image-Exp0.1_repackaged" + repository_file_path: "split_files/diffusion_models/NewBie-Image-Exp0.1-bf16.safetensors" + # ERNIE-Image + - filename: "ernie-image.safetensors" + source: "hf" + repo_id: "Comfy-Org/ERNIE-Image" + repository_file_path: "diffusion_models/ernie-image.safetensors" + - filename: "ernie-image-turbo.safetensors" + source: "hf" + repo_id: "Comfy-Org/ERNIE-Image" + repository_file_path: "diffusion_models/ernie-image-turbo.safetensors" + # FLUX.2-klein-9B-KV + - filename: "flux-2-klein-9b-kv-fp8.safetensors" + source: "hf" + repo_id: "black-forest-labs/FLUX.2-klein-9b-kv-fp8" + repository_file_path: "flux-2-klein-9b-kv-fp8.safetensors" # FLUX.2-klein-4B - filename: "flux-2-klein-4b-fp8.safetensors" source: "hf" @@ -25,8 +333,238 @@ file: source: "hf" repo_id: "Comfy-Org/flux2-dev" repository_file_path: "split_files/diffusion_models/flux2_dev_fp8mixed.safetensors" - + # LongCat-Image + - filename: "longcat_image_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/LongCat-Image" + repository_file_path: "split_files/diffusion_models/longcat_image_bf16.safetensors" + # Ovis-Image + - filename: "ovis_image_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/Ovis-Image" + repository_file_path: "split_files/diffusion_models/ovis_image_bf16.safetensors" + # Z-Image + - filename: "z_image_turbo_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/z_image_turbo" + repository_file_path: "split_files/diffusion_models/z_image_turbo_bf16.safetensors" + - filename: "z_image_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/z_image" + repository_file_path: "split_files/diffusion_models/z_image_bf16.safetensors" + # Qwen-Image + - filename: "qwen_image_2512_fp8_e4m3fn.safetensors" + source: "hf" + repo_id: "Comfy-Org/Qwen-Image_ComfyUI" + repository_file_path: "split_files/diffusion_models/qwen_image_2512_fp8_e4m3fn.safetensors" + - filename: "qwen_image_fp8_e4m3fn.safetensors" + source: "hf" + repo_id: "Comfy-Org/Qwen-Image_ComfyUI" + repository_file_path: "split_files/diffusion_models/qwen_image_fp8_e4m3fn.safetensors" + # Flux.1 + - filename: "flux1-dev-fp8-e4m3fn.safetensors" + source: "hf" + repo_id: "Kijai/flux-fp8" + repository_file_path: "flux1-dev-fp8-e4m3fn.safetensors" + - filename: "flux1-schnell-fp8-e4m3fn.safetensors" + source: "hf" + repo_id: "Kijai/flux-fp8" + repository_file_path: "flux1-schnell-fp8-e4m3fn.safetensors" + - filename: "flux1-dev-kontext_fp8_scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/flux1-kontext-dev_ComfyUI" + repository_file_path: "split_files/diffusion_models/flux1-dev-kontext_fp8_scaled.safetensors" + - filename: "flux1-krea-dev_fp8_scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/FLUX.1-Krea-dev_ComfyUI" + repository_file_path: "split_files/diffusion_models/flux1-krea-dev_fp8_scaled.safetensors" + # HiDream + - filename: "hidream_i1_dev_fp8.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hidream_i1_dev_fp8.safetensors" + - filename: "hidream_i1_fast_fp8.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hidream_i1_fast_fp8.safetensors" + - filename: "hidream_i1_full_fp8.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hidream_i1_full_fp8.safetensors" + - filename: "hunyuanimage2.1_fp8_e4m3fn.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hunyuanimage2.1_fp8_e4m3fn.safetensors" + - filename: "hunyuanimage2.1_distilled_fp8_e4m3fn.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hunyuanimage2.1_distilled_fp8_e4m3fn.safetensors" + - filename: "hunyuanimage2.1_refiner_fp8_e4m3fn.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/diffusion_models/hunyuanimage2.1_refiner_fp8_e4m3fn.safetensors" + # Chroma1-Radiance + - filename: "Chroma1-Radiance-x0-fp8mixed_fullmm-20260104.safetensors" + source: "hf" + repo_id: "silveroxides/Chroma1-Radiance-fp8-scaled" + repository_file_path: "Chroma1-Radiance-x0-fp8mixed_fullmm-20260104.safetensors" + # Chroma1 + - filename: "Chroma1-HD-Flash_float8_e4m3fn_scaled_learned_topk8_svd.safetensors" + source: "hf" + repo_id: "Clybius/Chroma-fp8-scaled" + repository_file_path: "Chroma1-HD/Chroma1-HD-Flash_float8_e4m3fn_scaled_learned_topk8_svd.safetensors" + - filename: "Chroma1-HD_float8_e4m3fn_scaled_learned_topk8_svd.safetensors" + source: "hf" + repo_id: "Clybius/Chroma-fp8-scaled" + repository_file_path: "Chroma1-HD/Chroma1-HD_float8_e4m3fn_scaled_learned_topk8_svd.safetensors" + - filename: "omnigen2_fp16.safetensors" + source: "hf" + repo_id: "Comfy-Org/Omnigen2_ComfyUI_repackaged" + repository_file_path: "split_files/diffusion_models/omnigen2_fp16.safetensors" + ipadapter: + # SD3.5 + - filename: "ip-adapter_sd35l_instantx.bin" + source: "hf" + repo_id: "InstantX/SD3.5-Large-IP-Adapter" + repository_file_path: "ip-adapter.bin" + # SD1.5 + - filename: "ip-adapter_sd15.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter_sd15.safetensors" + - filename: "ip-adapter_sd15_light_v11.bin" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter_sd15_light_v11.bin" + - filename: "ip-adapter-plus_sd15.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter-plus_sd15.safetensors" + - filename: "ip-adapter-plus-face_sd15.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter-plus-face_sd15.safetensors" + - filename: "ip-adapter-full-face_sd15.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter-full-face_sd15.safetensors" + - filename: "ip-adapter_sd15_vit-G.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "models/ip-adapter_sd15_vit-G.safetensors" + # SDXL + - filename: "ip-adapter_sdxl_vit-h.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "sdxl_models/ip-adapter_sdxl_vit-h.safetensors" + - filename: "ip-adapter-plus_sdxl_vit-h.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors" + - filename: "ip-adapter-plus-face_sdxl_vit-h.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "sdxl_models/ip-adapter-plus-face_sdxl_vit-h.safetensors" + - filename: "ip-adapter_sdxl.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter" + repository_file_path: "sdxl_models/ip-adapter_sdxl.safetensors" + - filename: "ip-adapter-faceid_sd15.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid_sd15.bin" + - filename: "ip-adapter-faceid-plusv2_sd15.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-plusv2_sd15.bin" + - filename: "ip-adapter-faceid-portrait-v11_sd15.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-portrait-v11_sd15.bin" + - filename: "ip-adapter-faceid_sdxl.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid_sdxl.bin" + - filename: "ip-adapter-faceid-plusv2_sdxl.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-plusv2_sdxl.bin" + - filename: "ip-adapter-faceid-portrait_sdxl.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-portrait_sdxl.bin" + - filename: "ip-adapter-faceid-portrait_sdxl_unnorm.bin" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-portrait_sdxl_unnorm.bin" + ipadapter-flux: + - filename: "ip-adapter.bin" + source: "hf" + repo_id: "InstantX/FLUX.1-dev-IP-Adapter" + repository_file_path: "ip-adapter.bin" + style_models: + # FLUX.1-Redux-dev + - filename: "flux1-redux-dev.safetensors" + source: "hf" + repo_id: "black-forest-labs/FLUX.1-Redux-dev" + repository_file_path: "flux1-redux-dev.safetensors" + loras: + # Qwen-Image + - filename: "Qwen-Image-2512-Lightning-4steps-V1.0-bf16.safetensors" + source: "hf" + repo_id: "lightx2v/Qwen-Image-2512-Lightning" + repository_file_path: "Qwen-Image-2512-Lightning-4steps-V1.0-bf16.safetensors" + - filename: "Qwen-Image-fp8-e4m3fn-Lightning-4steps-V1.0-bf16.safetensors" + source: "hf" + repo_id: "lightx2v/Qwen-Image-Lightning" + repository_file_path: "Qwen-Image-fp8-e4m3fn-Lightning-4steps-V1.0-bf16.safetensors" + # SD1.5 FaceID + - filename: "ip-adapter-faceid_sd15_lora.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid_sd15_lora.safetensors" + - filename: "ip-adapter-faceid-plusv2_sd15_lora.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-plusv2_sd15_lora.safetensors" + - filename: "ip-adapter-faceid_sdxl_lora.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid_sdxl_lora.safetensors" + - filename: "ip-adapter-faceid-plusv2_sdxl_lora.safetensors" + source: "hf" + repo_id: "h94/IP-Adapter-FaceID" + repository_file_path: "ip-adapter-faceid-plusv2_sdxl_lora.safetensors" + model_patches: + # Z-Image + - filename: "Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors" + source: "hf" + repo_id: "alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union-2.1" + repository_file_path: "Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors" + - filename: "Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors" + source: "hf" + repo_id: "alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union-2.1" + repository_file_path: "Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors" text_encoders: + # Anima + - filename: "qwen_3_06b_base.safetensors" + source: "hf" + repo_id: "circlestone-labs/Anima" + repository_file_path: "split_files/text_encoders/qwen_3_06b_base.safetensors" + # NewBie-Image + - filename: "gemma_3_4b_it_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/NewBie-image-Exp0.1_repackaged" + repository_file_path: "split_files/text_encoders/gemma_3_4b_it_bf16.safetensors" + - filename: "jina_clip_v2_bf16.safetensors" + source: "hf" + repo_id: "Comfy-Org/NewBie-image-Exp0.1_repackaged" + repository_file_path: "split_files/text_encoders/jina_clip_v2_bf16.safetensors" + # ERNIE-Image + - filename: "ministral-3-3b.safetensors" + source: "hf" + repo_id: "Comfy-Org/ERNIE-Image" + repository_file_path: "text_encoders/ministral-3-3b.safetensors" # FLUX.2-klein-4B & base - filename: "qwen_3_4b.safetensors" source: "hf" @@ -42,8 +580,65 @@ file: source: "hf" repo_id: "Comfy-Org/flux2-dev" repository_file_path: "split_files/text_encoders/mistral_3_small_flux2_fp8.safetensors" - + # Ovis-Image + - filename: "ovis_2.5.safetensors" + source: "hf" + repo_id: "Comfy-Org/Ovis-Image" + repository_file_path: "split_files/text_encoders/ovis_2.5.safetensors" + # Z-Image + - filename: "qwen_3_4b_fp8_mixed.safetensors" + source: "hf" + repo_id: "Comfy-Org/z_image_turbo" + repository_file_path: "split_files/text_encoders/qwen_3_4b_fp8_mixed.safetensors" + - filename: "clip_l.safetensors" + source: "hf" + repo_id: "comfyanonymous/flux_text_encoders" + repository_file_path: "clip_l.safetensors" + - filename: "t5xxl_fp8_e4m3fn_scaled.safetensors" + source: "hf" + repo_id: "comfyanonymous/flux_text_encoders" + repository_file_path: "t5xxl_fp8_e4m3fn_scaled.safetensors" + - filename: "clip_l_hidream.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/text_encoders/clip_l_hidream.safetensors" + - filename: "clip_g_hidream.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/text_encoders/clip_g_hidream.safetensors" + - filename: "llama_3.1_8b_instruct_fp8_scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/HiDream-I1_ComfyUI" + repository_file_path: "split_files/text_encoders/llama_3.1_8b_instruct_fp8_scaled.safetensors" + - filename: "qwen_2.5_vl_7b_fp8_scaled.safetensors" + source: "hf" + repo_id: "Comfy-Org/Qwen-Image_ComfyUI" + repository_file_path: "split_files/text_encoders/qwen_2.5_vl_7b_fp8_scaled.safetensors" + - filename: "byt5_small_glyphxl_fp16.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/text_encoders/byt5_small_glyphxl_fp16.safetensors" + - filename: "qwen_2.5_vl_fp16.safetensors" + source: "hf" + repo_id: "Comfy-Org/Omnigen2_ComfyUI_repackaged" + repository_file_path: "split_files/text_encoders/qwen_2.5_vl_fp16.safetensors" vae: + - filename: "qwen_image_vae.safetensors" + source: "hf" + repo_id: "Comfy-Org/Qwen-Image_ComfyUI" + repository_file_path: "split_files/vae/qwen_image_vae.safetensors" + - filename: "hunyuan_image_2.1_vae_fp16.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/vae/hunyuan_image_2.1_vae_fp16.safetensors" + - filename: "hunyuan_image_refiner_vae_fp16.safetensors" + source: "hf" + repo_id: "Comfy-Org/HunyuanImage_2.1_ComfyUI" + repository_file_path: "split_files/vae/hunyuan_image_refiner_vae_fp16.safetensors" + - filename: "ae.safetensors" + source: "hf" + repo_id: "Comfy-Org/Lumina_Image_2.0_Repackaged" + repository_file_path: "split_files/vae/ae.safetensors" - filename: "flux2-vae.safetensors" source: "hf" repo_id: "Comfy-Org/flux2-dev" diff --git a/yaml/image_gen_features.yaml b/yaml/image_gen_features.yaml new file mode 100644 index 0000000000000000000000000000000000000000..733507de35e081cddd9cf9ddf6803b5aaf746cc7 --- /dev/null +++ b/yaml/image_gen_features.yaml @@ -0,0 +1,117 @@ +default: + enabled_chains: + - lora + - controlnet + - ipadapter + - embedding + - style + - conditioning + +ernie-image: + enabled_chains: + - lora + - conditioning + +flux2: + enabled_chains: + - lora + - conditioning + - reference_latent + +flux2-kv: + enabled_chains: + - lora + - conditioning + - reference_latent + +z-image: + enabled_chains: + - lora + - conditioning + - controlnet_model_patch + +qwen-image: + enabled_chains: + - lora + - controlnet + - conditioning + +longcat-image: + enabled_chains: + - lora + - conditioning + +anima: + enabled_chains: + - lora + - conditioning + +newbie-image: + enabled_chains: + - lora + - embedding + - conditioning + +omnigen2: + enabled_chains: + - conditioning + - reference_latent + +lumina: + enabled_chains: + - lora + - embedding + - conditioning + +ovis-image: + enabled_chains: + - conditioning + +sd35: + enabled_chains: + - lora + - controlnet + - embedding + - conditioning + - sd3_ipadapter + +sdxl: + enabled_chains: + - lora + - controlnet + - ipadapter + - embedding + - conditioning + +sd15: + enabled_chains: + - lora + - controlnet + - ipadapter + - embedding + - conditioning + +flux1: + enabled_chains: + - lora + - controlnet + - style + - conditioning + - flux1_ipadapter + +hidream: + enabled_chains: + - lora + - conditioning + +chroma1: + enabled_chains: + - conditioning + +chroma1-radiance: + enabled_chains: + - conditioning + +hunyuanimage: + enabled_chains: + - conditioning \ No newline at end of file diff --git a/yaml/injectors.yaml b/yaml/injectors.yaml index fe45bdf002d47efd1deeb7b89bf92572c5622bd2..b592486debc458f19ce0d4e872fc57bd2a5f7264 100644 --- a/yaml/injectors.yaml +++ b/yaml/injectors.yaml @@ -1,12 +1,36 @@ injector_definitions: - dynamic_lora_chains: + dynamic_vae_chains: + module: "chain_injectors.vae_injector" + dynamic_lora_chains: module: "chain_injectors.lora_injector" + dynamic_newbie_lora_chains: + module: "chain_injectors.newbie_lora_injector" + dynamic_controlnet_chains: + module: "chain_injectors.controlnet_injector" + dynamic_diffsynth_controlnet_chains: + module: "chain_injectors.diffsynth_controlnet_injector" + dynamic_ipadapter_chains: + module: "chain_injectors.ipadapter_injector" + dynamic_flux1_ipadapter_chains: + module: "chain_injectors.flux1_ipadapter_injector" + dynamic_sd3_ipadapter_chains: + module: "chain_injectors.sd3_ipadapter_injector" + dynamic_style_chains: + module: "chain_injectors.style_injector" dynamic_conditioning_chains: module: "chain_injectors.conditioning_injector" dynamic_reference_latent_chains: module: "chain_injectors.reference_latent_injector" injector_order: + - dynamic_vae_chains - dynamic_lora_chains + - dynamic_newbie_lora_chains + - dynamic_diffsynth_controlnet_chains + - dynamic_ipadapter_chains + - dynamic_flux1_ipadapter_chains + - dynamic_sd3_ipadapter_chains + - dynamic_style_chains + - dynamic_conditioning_chains - dynamic_reference_latent_chains - - dynamic_conditioning_chains \ No newline at end of file + - dynamic_controlnet_chains \ No newline at end of file diff --git a/yaml/ipadapter.yaml b/yaml/ipadapter.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6fed9eddbfcf91ed4b31a9b8550810cff9b20d40 --- /dev/null +++ b/yaml/ipadapter.yaml @@ -0,0 +1,25 @@ +IPAdapter_presets: + SD1.5: + - "LIGHT - SD1.5 only (low strength)" + - "STANDARD (medium strength)" + - "VIT-G (medium strength)" + - "PLUS (high strength)" + - "PLUS FACE (portraits)" + - "FULL FACE - SD1.5 only (portraits stronger)" + SDXL: + - "STANDARD (medium strength)" + - "VIT-G (medium strength)" + - "PLUS (high strength)" + - "PLUS FACE (portraits)" + +IPAdapter_FaceID_presets: + SD1.5: + - "FACEID" + - "FACEID PLUS - SD1.5 only" + - "FACEID PLUS V2" + - "FACEID PORTRAIT (style transfer)" + SDXL: + - "FACEID" + - "FACEID PLUS V2" + - "FACEID PORTRAIT (style transfer)" + - "FACEID PORTRAIT UNNORM - SDXL only (strong)" \ No newline at end of file diff --git a/yaml/ipadapter_models.yaml b/yaml/ipadapter_models.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f87d6b21c8415cce1ea8bbe3fabff36543d05fa1 --- /dev/null +++ b/yaml/ipadapter_models.yaml @@ -0,0 +1,55 @@ +- preset_name: "LIGHT - SD1.5 only (low strength)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter_sd15_light_v11.bin" + +- preset_name: "STANDARD (medium strength)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter_sdxl_vit-h.safetensors" + ipadapter: "ip-adapter_sd15.safetensors" + +- preset_name: "VIT-G (medium strength)" + clip_vision: "CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors" + ipadapter: "ip-adapter_sdxl.safetensors" + ipadapter: "ip-adapter_sd15_vit-G.safetensors" + +- preset_name: "PLUS (high strength)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-plus_sdxl_vit-h.safetensors" + ipadapter: "ip-adapter-plus_sd15.safetensors" + +- preset_name: "PLUS FACE (portraits)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-plus-face_sdxl_vit-h.safetensors" + ipadapter: "ip-adapter-plus-face_sd15.safetensors" + +- preset_name: "FULL FACE - SD1.5 only (portraits stronger)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-full-face_sd15.safetensors" + +- preset_name: "FACEID" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-faceid_sdxl.bin" + loras: "ip-adapter-faceid_sdxl_lora.safetensors" + ipadapter: "ip-adapter-faceid_sd15.bin" + loras: "ip-adapter-faceid_sd15_lora.safetensors" + +- preset_name: "FACEID PLUS - SD1.5 only" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-faceid-plus_sd15.bin" + loras: "ip-adapter-faceid-plus_sd15_lora.safetensors" + +- preset_name: "FACEID PLUS V2" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-faceid-plusv2_sdxl.bin" + loras: "ip-adapter-faceid-plusv2_sdxl_lora.safetensors" + ipadapter: "ip-adapter-faceid-plusv2_sd15.bin" + loras: "ip-adapter-faceid-plusv2_sd15_lora.safetensors" + +- preset_name: "FACEID PORTRAIT (style transfer)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-faceid-portrait_sdxl.bin" + ipadapter: "ip-adapter-faceid-portrait-v11_sd15.bin" + +- preset_name: "FACEID PORTRAIT UNNORM - SDXL only (strong)" + clip_vision: "CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors" + ipadapter: "ip-adapter-faceid-portrait_sdxl_unnorm.bin" diff --git a/yaml/ipadapter_sd3_models.yaml b/yaml/ipadapter_sd3_models.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d80c4da70e9863b38863cdae6e9112a2fad246a --- /dev/null +++ b/yaml/ipadapter_sd3_models.yaml @@ -0,0 +1,2 @@ +ipadapter: "ip-adapter_sd35l_instantx.bin" +clip_vision: "sigclip_vision_patch14_384.safetensors" \ No newline at end of file diff --git a/yaml/model_architectures.yaml b/yaml/model_architectures.yaml new file mode 100644 index 0000000000000000000000000000000000000000..011b825f858e566a28855e1ef9185d271d70045f --- /dev/null +++ b/yaml/model_architectures.yaml @@ -0,0 +1,79 @@ +architecture_order: + - "FLUX.2-KV" + - "FLUX.2" + - "ERNIE-Image" + - "Z-Image" + - "Qwen-Image" + - "LongCat-Image" + - "Anima" + - "NewBie-Image" + - "Ovis-Image" + - "HunyuanImage" + - "Chroma1-Radiance" + - "Chroma1" + - "OmniGen2" + - "Lumina" + - "HiDream" + - "FLUX.1" + - "SD3.5" + - "SDXL" + - "SD1.5" + +architectures: + "ERNIE-Image": + model_type: "ernie-image" + controlnet_key: "ERNIE-Image" + "FLUX.2-KV": + model_type: "flux2-kv" + controlnet_key: "FLUX.2" + "FLUX.2": + model_type: "flux2" + controlnet_key: "FLUX.2" + "Z-Image": + model_type: "z-image" + controlnet_key: "Z-Image" + "Qwen-Image": + model_type: "qwen-image" + controlnet_key: "Qwen-Image" + "LongCat-Image": + model_type: "longcat-image" + controlnet_key: "LongCat-Image" + "Anima": + model_type: "anima" + controlnet_key: "Anima" + "Chroma1-Radiance": + model_type: "chroma1-radiance" + controlnet_key: "Chroma1-Radiance" + "Chroma1": + model_type: "chroma1" + controlnet_key: "Chroma1" + "OmniGen2": + model_type: "omnigen2" + controlnet_key: "OmniGen2" + "Lumina": + model_type: "lumina" + controlnet_key: "Lumina" + "Ovis-Image": + model_type: "ovis-image" + controlnet_key: "Ovis-Image" + "HunyuanImage": + model_type: "hunyuanimage" + controlnet_key: "HunyuanImage" + "NewBie-Image": + model_type: "newbie-image" + controlnet_key: "NewBie-Image" + "FLUX.1": + model_type: "flux1" + controlnet_key: "FLUX.1" + "SDXL": + model_type: "sdxl" + controlnet_key: "SDXL" + "SD3.5": + model_type: "sd35" + controlnet_key: "SD3.5" + "HiDream": + model_type: "hidream" + controlnet_key: "HiDream" + "SD1.5": + model_type: "sd15" + controlnet_key: "SD1.5" \ No newline at end of file diff --git a/yaml/model_defaults.yaml b/yaml/model_defaults.yaml index 090d052d63bf1c14201927e20a44fa894fbdd0e4..3620a4b52629cd0a58d3e3edcf33550d0b35812d 100644 --- a/yaml/model_defaults.yaml +++ b/yaml/model_defaults.yaml @@ -1,8 +1,25 @@ Default: - steps: 20 - cfg: 4.0 + steps: 25 + cfg: 7.0 sampler_name: "euler" scheduler: "simple" + total_pixels: 1048576 + positive_prompt: "" + negative_prompt: "" + +ERNIE-Image: + _defaults: + steps: 20 + cfg: 4.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 + "baidu/ERNIE-Image-Turbo": + steps: 8 + cfg: 1.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 FLUX.2: _defaults: @@ -10,9 +27,180 @@ FLUX.2: cfg: 4.0 sampler_name: "euler" scheduler: "simple" + total_pixels: 1048576 "black-forest-labs/FLUX.2-klein-4B": steps: 4 cfg: 1.0 "black-forest-labs/FLUX.2-klein-9B": steps: 4 + cfg: 1.0 + +FLUX.2-KV: + _defaults: + steps: 20 + cfg: 4.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 + "black-forest-labs/FLUX.2-klein-9B-KV": + steps: 4 + cfg: 1.0 + +Z-Image: + _defaults: + steps: 25 + cfg: 4.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 + "Tongyi-MAI/Z Image Turbo": + steps: 9 + cfg: 1.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 + +Qwen-Image: + _defaults: + steps: 4 + cfg: 1.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1763584 + +LongCat-Image: + _defaults: + steps: 20 + cfg: 4.0 + guidance: 4.0 + sampler_name: "euler" + scheduler: "simple" + total_pixels: 1048576 + +Anima: + _defaults: + steps: 30 + cfg: 4.0 + sampler_name: "er_sde" + scheduler: "simple" + total_pixels: 1048576 + positive_prompt: "masterpiece, best quality, score_7, safe. " + negative_prompt: "worst quality, low quality, score_1, score_2, score_3, blurry, jpeg artifacts, sepia" + +NewBie-Image: + _defaults: + steps: 20 + cfg: 5.5 + sampler_name: "res_multistep" + scheduler: "simple" + positive_prompt: "You are an assistant designed to generate high-quality anime images with the highest degree of image-text alignment based on xml format textual prompts.