Add easy loraSwitcher

This commit is contained in:
yolain
2025-07-26 17:20:39 +08:00
parent 8c1eec2858
commit 14a1121860
8 changed files with 93 additions and 10 deletions
+25
View File
@@ -1154,6 +1154,31 @@
}
}
},
"easy loraSwitcher": {
"display_name": "简易Lora切换器",
"inputs": {
"optional_lora_stack": {
"name": "LoRA堆(可选)"
},
"toggle": {
"name": "开关"
},
"select": {
"name": "选择项"
},
"num_loras": {
"name": "LoRA数量"
}
},
"outputs": {
"0": {
"name": "LoRA堆"
},
"1": {
"name": "LoRA名称"
}
}
},
"easy controlnetStack": {
"display_name": "简易 ControlNet 堆",
"inputs": {
+55 -2
View File
@@ -8,7 +8,7 @@ from nodes import MAX_RESOLUTION, NODE_CLASS_MAPPINGS as ALL_NODE_CLASS_MAPPINGS
from ..libs.log import log_node_info, log_node_error, log_node_warn
from ..libs.wildcards import process_with_loras
from ..libs.utils import find_wildcards_seed, is_linked_styles_selector, get_sd_version
from ..libs.utils import find_wildcards_seed, is_linked_styles_selector, get_sd_version, AlwaysEqualProxy
from ..libs.sampler import easySampler
from ..libs.controlnet import easyControlnet, union_controlnet_types
from ..libs.conditioning import prompt_to_cond
@@ -19,6 +19,7 @@ from ..config import *
from .. import easyCache, sampler
any_type = AlwaysEqualProxy("*")
# 简易加载器完整
resolution_strings = [f"{width} x {height} (custom)" if width == 'width' and height == 'height' else f"{width} x {height}" for width, height in BASE_RESOLUTIONS]
class fullLoader:
@@ -1146,6 +1147,56 @@ class mochiLoader(fullLoader):
my_unique_id=my_unique_id
)
# lora
class loraSwitcher:
@classmethod
def INPUT_TYPES(s):
max_lora_num = 50
inputs = {
"required": {
"toggle": ("BOOLEAN", {"label_on": "on", "label_off": "off"}),
"select": ("INT", {"default": 1, "min": 1, "max": max_lora_num}),
"num_loras": ("INT", {"default": 1, "min": 1, "max": max_lora_num}),
"lora_strength": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01})
},
"optional": {
"optional_lora_stack": ("LORA_STACK",),
},
}
for i in range(1, max_lora_num + 1):
inputs["optional"][f"lora_{i}_name"] = (
["None"] + folder_paths.get_filename_list("loras"), {"default": "None"})
return inputs
RETURN_TYPES = ("LORA_STACK", any_type)
RETURN_NAMES = ("lora_stack", "lora_name")
FUNCTION = "stack"
CATEGORY = "EasyUse/Loaders"
def stack(self, toggle, select,num_loras, lora_strength, optional_lora_stack=None, **kwargs):
if (toggle in [False, None, "False"]) or not kwargs:
return (None,'')
loras = []
# Import Stack values
if optional_lora_stack is not None:
loras.extend([l for l in optional_lora_stack if l[0] != "None"])
# Import Lora values
lora_name = kwargs.get(f"lora_{select}_name")
if not lora_name or lora_name == "None":
return (None,'')
loras.append((lora_name, lora_strength, lora_strength))
name = os.path.splitext(os.path.basename(str(lora_name)))[0]
return (loras, name)
class loraStack:
def __init__(self):
pass
@@ -1155,7 +1206,7 @@ class loraStack:
max_lora_num = 10
inputs = {
"required": {
"toggle": ("BOOLEAN", {"label_on": "enabled", "label_off": "disabled"}),
"toggle": ("BOOLEAN", {"label_on": "on", "label_off": "off"}),
"mode": (["simple", "advanced"],),
"num_loras": ("INT", {"default": 1, "min": 1, "max": max_lora_num}),
},
@@ -1482,6 +1533,7 @@ NODE_CLASS_MAPPINGS = {
"easy hunyuanDiTLoader": hunyuanDiTLoader,
"easy pixArtLoader": pixArtLoader,
"easy mochiLoader": mochiLoader,
"easy loraSwitcher": loraSwitcher,
"easy loraStack": loraStack,
"easy controlnetStack": controlnetStack,
"easy controlnetLoader": controlnetSimple,
@@ -1503,6 +1555,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"easy hunyuanDiTLoader": "EasyLoader (HunyuanDiT)",
"easy pixArtLoader": "EasyLoader (PixArt)",
"easy mochiLoader": "EasyLoader (Mochi)",
"easy loraSwitcher": "EasyLoraSwitcher",
"easy loraStack": "EasyLoraStack",
"easy controlnetStack": "EasyControlnetStack",
"easy controlnetLoader": "EasyControlnet",
+4 -2
View File
@@ -1369,10 +1369,12 @@ class showAnything:
if "anything" in kwargs:
for val in kwargs['anything']:
try:
if type(val) is str:
if isinstance(val, str):
values.append(val)
elif type(val) is list:
elif isinstance(val, list):
values = val
elif isinstance(val, (int, float, bool)):
values.append(str(val))
else:
val = json.dumps(val)
values.append(str(val))
+5 -2
View File
@@ -113,7 +113,7 @@ async def getStylesList(request):
if isinstance(d['thumbnail'], str):
nd['thumbnail'] = thumbnail if "http" in thumbnail else f'/easyuse/prompt/styles/image?path={thumbnail}'
elif isinstance(d['thumbnail'], list):
nd['thumbnail'] = thumbnail
nd['thumbnail'] = [thumb if "http" in thumb else f'/easyuse/prompt/styles/image?path={thumb}' for thumb in thumbnail]
else:
nd['thumbnail'] = f'/easyuse/prompt/styles/image?name={name}&styles_name={style_name}'
if "thumbnail_variant" in d:
@@ -136,9 +136,12 @@ async def getStylesImage(request):
styles_name = request.rel_url.query["styles_name"] if "styles_name" in request.rel_url.query else None
if "path" in request.rel_url.query:
path = request.rel_url.query["path"]
file = os.path.join(FOOOCUS_STYLES_DIR, path)
file = os.path.join(FOOOCUS_STYLES_DIR, 'samples', path)
parent_file = os.path.join(FOOOCUS_STYLES_DIR, path)
if os.path.isfile(file):
return web.FileResponse(file)
elif os.path.isfile(parent_file):
return web.FileResponse(parent_file)
elif "name" in request.rel_url.query:
name = request.rel_url.query["name"]
if os.path.exists(os.path.join(FOOOCUS_STYLES_DIR, 'samples')):
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long