From a7ff534938a27098ce515f18888c2c0d61117c96 Mon Sep 17 00:00:00 2001 From: Guilherme Rizzo Date: Mon, 20 Jan 2025 18:07:06 +0800 Subject: [PATCH 1/5] Add support for custom lora urls in LoRA Stacker --- comfyui.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/comfyui.py b/comfyui.py index cf39f93c..8964d4ee 100644 --- a/comfyui.py +++ b/comfyui.py @@ -358,3 +358,33 @@ def convert_lora_loader_nodes(self, workflow): node["class_type"] = "LoraLoaderFromURL" node["inputs"]["url"] = inputs["lora_name"] del node["inputs"]["lora_name"] + + # Handle LoRA Stacker nodes + elif node.get("class_type") == "LoRA Stacker": + inputs = node.get("inputs", {}) + # Look for numbered lora_name fields (lora_name_1, lora_name_2, etc.) + for key in list(inputs.keys()): + if key.startswith("lora_name_") and isinstance(inputs[key], str): + value = inputs[key] + if value.startswith(("http://", "https://")): + # Create local filename without query parameters + local_filename = os.path.basename(value.split('?')[0]) + + # Create custom weights map for this download + custom_weights_map = { + local_filename: { + "url": value, + "dest": "ComfyUI/models/loras/" + } + } + + try: + self.weights_downloader.download_if_not_exists( + local_filename, + custom_weights_map[local_filename]["url"], + custom_weights_map[local_filename]["dest"] + ) + # Update the input to use the local filename + inputs[key] = local_filename + except Exception as e: + print(f"❌ Error downloading LoRA from {value}: {e}") From 2239c71027e34253c0478f58ad67d6dcc248e6ce Mon Sep 17 00:00:00 2001 From: Guilherme Rizzo Date: Tue, 28 Jan 2025 19:09:34 +0800 Subject: [PATCH 2/5] Only download .safetensors files for Lora Stacker + hash filenames --- comfyui.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/comfyui.py b/comfyui.py index 8964d4ee..ece16fb8 100644 --- a/comfyui.py +++ b/comfyui.py @@ -15,6 +15,7 @@ from node import Node from weights_downloader import WeightsDownloader from urllib.error import URLError +import hashlib class ComfyUI: @@ -367,9 +368,15 @@ def convert_lora_loader_nodes(self, workflow): if key.startswith("lora_name_") and isinstance(inputs[key], str): value = inputs[key] if value.startswith(("http://", "https://")): - # Create local filename without query parameters - local_filename = os.path.basename(value.split('?')[0]) - + # Verify file extension is .safetensors + if not value.lower().split("?")[0].endswith(".safetensors"): + print(f"❌ Skipping LoRA from {value}: Only .safetensors files are supported for security reasons") + continue + + # Create unique filename by hashing the URL + hashed_filename = hashlib.md5(value.encode()).hexdigest() + local_filename = f"{hashed_filename}.safetensors" + # Create custom weights map for this download custom_weights_map = { local_filename: { @@ -377,7 +384,7 @@ def convert_lora_loader_nodes(self, workflow): "dest": "ComfyUI/models/loras/" } } - + try: self.weights_downloader.download_if_not_exists( local_filename, From d02e6bd01942463afaaccf746d4b97aa4e1d59a6 Mon Sep 17 00:00:00 2001 From: Guilherme Rizzo Date: Tue, 28 Jan 2025 19:37:01 +0800 Subject: [PATCH 3/5] Change error messages on LoRA Stacker custom LoRA downloads --- comfyui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comfyui.py b/comfyui.py index ece16fb8..61aa6c4c 100644 --- a/comfyui.py +++ b/comfyui.py @@ -370,7 +370,7 @@ def convert_lora_loader_nodes(self, workflow): if value.startswith(("http://", "https://")): # Verify file extension is .safetensors if not value.lower().split("?")[0].endswith(".safetensors"): - print(f"❌ Skipping LoRA from {value}: Only .safetensors files are supported for security reasons") + print(f"❌ Skipping LoRA from {value}: Only .safetensors files are supported") continue # Create unique filename by hashing the URL From d53308db583938d6bcb796c4b58ad904880b82be Mon Sep 17 00:00:00 2001 From: Guilherme Rizzo Date: Sat, 1 Feb 2025 16:15:01 +0800 Subject: [PATCH 4/5] make LoRA Stacker lora downloader code clearer --- comfyui.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/comfyui.py b/comfyui.py index 61aa6c4c..07644fbb 100644 --- a/comfyui.py +++ b/comfyui.py @@ -373,25 +373,17 @@ def convert_lora_loader_nodes(self, workflow): print(f"❌ Skipping LoRA from {value}: Only .safetensors files are supported") continue - # Create unique filename by hashing the URL - hashed_filename = hashlib.md5(value.encode()).hexdigest() - local_filename = f"{hashed_filename}.safetensors" - - # Create custom weights map for this download - custom_weights_map = { - local_filename: { - "url": value, - "dest": "ComfyUI/models/loras/" - } - } - try: + # Create unique filename by hashing the URL + hashed_filename = hashlib.md5(value.encode()).hexdigest() + ".safetensors" + dest = "ComfyUI/models/loras/" + self.weights_downloader.download_if_not_exists( - local_filename, - custom_weights_map[local_filename]["url"], - custom_weights_map[local_filename]["dest"] + hashed_filename, + value, + dest ) - # Update the input to use the local filename - inputs[key] = local_filename + # Update the input to use the local hashed filename + inputs[key] = hashed_filename except Exception as e: print(f"❌ Error downloading LoRA from {value}: {e}") From 39c15dfd79fd2f9a9a8fa91ea34d80cc78538168 Mon Sep 17 00:00:00 2001 From: Guilherme Rizzo Date: Sat, 1 Feb 2025 16:33:25 +0800 Subject: [PATCH 5/5] keep original filename on custom lora (from lora stacker) to improve logs --- comfyui.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/comfyui.py b/comfyui.py index 07644fbb..327014bd 100644 --- a/comfyui.py +++ b/comfyui.py @@ -374,8 +374,13 @@ def convert_lora_loader_nodes(self, workflow): continue try: - # Create unique filename by hashing the URL - hashed_filename = hashlib.md5(value.encode()).hexdigest() + ".safetensors" + # Extract base filename without extension from URL + url_without_params = value.split("?")[0] + filename = os.path.basename(url_without_params) + filename_without_extension = os.path.splitext(filename)[0] + # Generate unique filename by combining the original name with a URL hash + hashed_url = hashlib.md5(value.encode()).hexdigest()[:8] + hashed_filename = f"{filename_without_extension}_{hashed_url}.safetensors" dest = "ComfyUI/models/loras/" self.weights_downloader.download_if_not_exists(