mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-22 05:32:12 -03:00
Move the 'empty/no LoRA' cycling functionality from the LoRA Pool node to the Lora Cycler widget for cleaner architecture: Frontend changes: - Add include_no_lora field to CyclerConfig interface - Add includeNoLora state and logic to useLoraCyclerState composable - Add toggle UI in LoraCyclerSettingsView with special styling - Show 'No LoRA' entry in LoraListModal when enabled - Update LoraCyclerWidget to integrate new logic Backend changes: - lora_cycler.py reads include_no_lora from config - Calculate effective_total_count (actual count + 1 when enabled) - Return empty lora_stack when on No LoRA position - Return actual LoRA count in total_count (not effective count) Reverted files to pre-PR state: - lora_loader.py, lora_pool.py, lora_randomizer.py, lora_stacker.py - lora_routes.py, lora_service.py - LoraPoolWidget.vue and related files Related to PR #861 Co-authored-by: dogatech <dogatech@dogatech.home>
83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
import os
|
|
from ..utils.utils import get_lora_info
|
|
from .utils import FlexibleOptionalInputType, any_type, extract_lora_name, get_loras_list
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class LoraStackerLM:
|
|
NAME = "Lora Stacker (LoraManager)"
|
|
CATEGORY = "Lora Manager/stackers"
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"text": ("AUTOCOMPLETE_TEXT_LORAS", {
|
|
"placeholder": "Search LoRAs to add...",
|
|
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
|
}),
|
|
},
|
|
"optional": FlexibleOptionalInputType(any_type),
|
|
}
|
|
|
|
RETURN_TYPES = ("LORA_STACK", "STRING", "STRING")
|
|
RETURN_NAMES = ("LORA_STACK", "trigger_words", "active_loras")
|
|
FUNCTION = "stack_loras"
|
|
|
|
def stack_loras(self, text, **kwargs):
|
|
"""Stacks multiple LoRAs based on the kwargs input without loading them."""
|
|
stack = []
|
|
active_loras = []
|
|
all_trigger_words = []
|
|
|
|
# Process existing lora_stack if available
|
|
lora_stack = kwargs.get('lora_stack', None)
|
|
if (lora_stack):
|
|
stack.extend(lora_stack)
|
|
# Get trigger words from existing stack entries
|
|
for lora_path, _, _ in lora_stack:
|
|
lora_name = extract_lora_name(lora_path)
|
|
_, trigger_words = get_lora_info(lora_name)
|
|
all_trigger_words.extend(trigger_words)
|
|
|
|
# Process loras from kwargs with support for both old and new formats
|
|
loras_list = get_loras_list(kwargs)
|
|
for lora in loras_list:
|
|
if not lora.get('active', False):
|
|
continue
|
|
|
|
lora_name = lora['name']
|
|
model_strength = float(lora['strength'])
|
|
# Get clip strength - use model strength as default if not specified
|
|
clip_strength = float(lora.get('clipStrength', model_strength))
|
|
|
|
# Get lora path and trigger words
|
|
lora_path, trigger_words = get_lora_info(lora_name)
|
|
|
|
# Add to stack without loading
|
|
# replace '/' with os.sep to avoid different OS path format
|
|
stack.append((lora_path.replace('/', os.sep), model_strength, clip_strength))
|
|
active_loras.append((lora_name, model_strength, clip_strength))
|
|
|
|
# Add trigger words to collection
|
|
all_trigger_words.extend(trigger_words)
|
|
|
|
# use ',, ' to separate trigger words for group mode
|
|
trigger_words_text = ",, ".join(all_trigger_words) if all_trigger_words else ""
|
|
|
|
# Format active_loras with support for both formats
|
|
formatted_loras = []
|
|
for name, model_strength, clip_strength in active_loras:
|
|
if abs(model_strength - clip_strength) > 0.001:
|
|
# Different model and clip strengths
|
|
formatted_loras.append(f"<lora:{name}:{str(model_strength).strip()}:{str(clip_strength).strip()}>")
|
|
else:
|
|
# Same strength for both
|
|
formatted_loras.append(f"<lora:{name}:{str(model_strength).strip()}>")
|
|
|
|
active_loras_text = " ".join(formatted_loras)
|
|
|
|
return (stack, trigger_words_text, active_loras_text)
|