From b4c27bbbea61ac1170730329d6d2b651367e2ec7 Mon Sep 17 00:00:00 2001 From: nick Date: Wed, 24 Apr 2024 23:27:01 -0700 Subject: [PATCH] fix: external lora --- comfy-nodes/external_lora.py | 44 ++++++++++++++++++++---------------- custom_routes.py | 3 +++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/comfy-nodes/external_lora.py b/comfy-nodes/external_lora.py index f186ba2..ad47d62 100644 --- a/comfy-nodes/external_lora.py +++ b/comfy-nodes/external_lora.py @@ -16,8 +16,8 @@ class ComfyUIDeployExternalLora: ), }, "optional": { - "default_lora_name": (folder_paths.get_filename_list("loras"), ), - } + "default_lora_name": (folder_paths.get_filename_list("loras"),), + }, } RETURN_TYPES = (folder_paths.get_filename_list("loras"),) @@ -32,23 +32,29 @@ class ComfyUIDeployExternalLora: import os import uuid - if input_id: - if input_id.startswith('http'): - unique_filename = str(uuid.uuid4()) + ".safetensors" - print(unique_filename) - print(folder_paths.folder_names_and_paths["loras"][0][0]) - destination_path = os.path.join(folder_paths.folder_names_and_paths["loras"][0][0], unique_filename) - print(destination_path) - print("Downloading external lora - " + input_id + " to " + destination_path) - response = requests.get(input_id, headers={'User-Agent': 'Mozilla/5.0'}, allow_redirects=True) - with open(destination_path, 'wb') as out_file: - out_file.write(response.content) - return (unique_filename,) - else: - return (input_id,) + if default_lora_name.startswith("http"): + unique_filename = str(uuid.uuid4()) + ".safetensors" + print(unique_filename) + print(folder_paths.folder_names_and_paths["loras"][0][0]) + destination_path = os.path.join( + folder_paths.folder_names_and_paths["loras"][0][0], unique_filename + ) + print(destination_path) + print("Downloading external lora - " + input_id + " to " + destination_path) + response = requests.get( + input_id, + headers={"User-Agent": "Mozilla/5.0"}, + allow_redirects=True, + ) + with open(destination_path, "wb") as out_file: + out_file.write(response.content) + return (unique_filename,) + else: + print(f"using lora: {default_lora_name}") + return (default_lora_name,) - return (default_lora_name,) - NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalLora": ComfyUIDeployExternalLora} -NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalLora": "External Lora (ComfyUI Deploy)"} \ No newline at end of file +NODE_DISPLAY_NAME_MAPPINGS = { + "ComfyUIDeployExternalLora": "External Lora (ComfyUI Deploy)" +} diff --git a/custom_routes.py b/custom_routes.py index db8319c..a8531fc 100644 --- a/custom_routes.py +++ b/custom_routes.py @@ -137,6 +137,9 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None): if (value["class_type"] == "ComfyUIDeployExternalImageBatch"): value['inputs']["images"] = new_value + + if value["class_type"] == "ComfyUIDeployExternalLora": + value["inputs"]["default_lora_name"] = new_value def send_prompt(sid: str, inputs: StreamingPrompt): # workflow_api = inputs.workflow_api