idrirap / ComfyUI-Lora-Auto-Trigger-Words

103 stars 7 forks source link

Improvement proposal to have more felxibility on lora_name input and get to extract lora tags without loading it : #8

Closed yoda5477 closed 7 months ago

yoda5477 commented 7 months ago

class LoraTagsExtractVanilla: def init(self): self.loaded_lora = None

@classmethod
def INPUT_TYPES(s):
    LORA_LIST = sorted(folder_paths.get_filename_list("loras"), key=str.lower)
    return {
        "required": { 
            "lora_name": ("STRING", {
                "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
                "default": (sorted(folder_paths.get_filename_list("loras"), key=str.lower), )
            }),
            "force_fetch": ("BOOLEAN", {"default": False}),
            "append_loraname_if_empty": ("BOOLEAN", {"default": False}),
        }
    }

RETURN_TYPES = ("LIST", "LIST")
RETURN_NAMES = ("civitai_tags_list", "meta_tags_list")
FUNCTION = "ask_lora"
CATEGORY = "autotrigger"

def ask_lora(self, lora_name, force_fetch, append_loraname_if_empty):
    meta_tags_list = sort_tags_by_frequency(get_metadata(lora_name, "loras"))
    civitai_tags_list = load_and_save_tags(lora_name, force_fetch)

    meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name, append_loraname_if_empty)
    civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name, append_loraname_if_empty)

    lora_path = folder_paths.get_full_path("loras", lora_name)

    return (civitai_tags_list, meta_tags_list)

idrirap commented 7 months ago

Hello, ok so if I get it correctly, what you want is a loader which will only output the lists of tags. And that has a string dynamic name that can be defined manually ?

idrirap commented 7 months ago

Something like that ? where you can write any name in the lora field, without the drop down menu ? image

yoda5477 commented 7 months ago

More like somthing where you still have the drop-down when using the widget but you can link a text field if used as input. The code I found in another node somewhere else where it works.

On Tue, Dec 12, 2023 at 5:41 PM dijkstra @.***> wrote:

Something like that ? where you can write any name in the lora field, without the drop down menu ? image.png (view on web) https://github.com/idrirap/ComfyUI-Lora-Auto-Trigger-Words/assets/17302538/2e767c09-3139-4244-a63f-ac98aa488f3c

— Reply to this email directly, view it on GitHub https://github.com/idrirap/ComfyUI-Lora-Auto-Trigger-Words/issues/8#issuecomment-1852409414, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZKFDN5LO3UCJY5G6E7OJLYJCCMJAVCNFSM6AAAAABAQMM5QCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJSGQYDSNBRGQ . You are receiving this because you authored the thread.Message ID: @.***>

yoda5477 commented 7 months ago

What my changes did exactly. Would also be good to have the modified input type on all your nodes as it simply allow for text link and changes nothing else.

On Tue, Dec 12, 2023 at 5:27 PM dijkstra @.***> wrote:

Ok so if I get it correctly, what you want is a loader which will only output the lists of tags. And that has a string dynamic name that can be defined manually ?

— Reply to this email directly, view it on GitHub https://github.com/idrirap/ComfyUI-Lora-Auto-Trigger-Words/issues/8#issuecomment-1852381405, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZKFDLCSZOPX5ECSPRT3OLYJCAVLAVCNFSM6AAAAABAQMM5QCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJSGM4DCNBQGU . You are receiving this because you authored the thread.Message ID: @.***>

idrirap commented 7 months ago

Ok I get it ! Good idea

idrirap commented 7 months ago

So I added the new node "LoraTagsOnly" which will only load tags and not the actual loras. And I added an option input in which you can input any string that will override the lora name. I added a dropdown menu that will output the lora name as a string. So you can input it in the override. I hope it is what you expected image

yoda5477 commented 7 months ago

So I added the new node "LoraTagsOnly" which will only load tags and not the actual loras. And I added an option input in which you can input any string that will override the lora name. I added a dropdown menu that will output the lora name as a string. So you can input it in the override. I hope it is what you expected image

Not sure why you needed to add a new input rather than the simple change I proposed than seems to have same behavior when lora_name is set as input instead of widget. Guess I must have missed something

idrirap commented 7 months ago

I don't think I can cast a "combo" type into a "string" type. It's not compatible. I can either have a drop down or a string. Not both. or at least I did not find a way to achieve it

yoda5477 commented 7 months ago

Here is my whole new function. Ok if not to your likig, I can always keep my commit ontop of yours locally, thanks for the nodes in any case !


class LoraTagsExtractVanilla: def init(self): self.loaded_lora = None

@classmethod
def INPUT_TYPES(s):
    LORA_LIST = sorted(folder_paths.get_filename_list("loras"), key=str.lower)
    return {
        "required": { 
            "lora_name": ("STRING", {
                "multiline": False, 
                "default": (sorted(folder_paths.get_filename_list("loras"), key=str.lower), )
            }),
            "force_fetch": ("BOOLEAN", {"default": False}),
            "append_loraname_if_empty": ("BOOLEAN", {"default": False}),
        }
    }

RETURN_TYPES = ("LIST", "LIST")
RETURN_NAMES = ("civitai_tags_list", "meta_tags_list")
FUNCTION = "ask_lora"
CATEGORY = "autotrigger"

def ask_lora(self, lora_name, force_fetch, append_loraname_if_empty):
    meta_tags_list = sort_tags_by_frequency(get_metadata(lora_name, "loras"))
    civitai_tags_list = load_and_save_tags(lora_name, force_fetch)

    meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name, append_loraname_if_empty)
    civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name, append_loraname_if_empty)

    lora_path = folder_paths.get_full_path("loras", lora_name)

    return (civitai_tags_list, meta_tags_list)

idrirap commented 7 months ago

I may not understand it correctly, because when I tried to implement your code, the lora_name field was just a text area filled the name of all my loras separated with a comma. This was not interpreted correctly by the other functions. And did not allow for a dropdown menu.

yoda5477 commented 7 months ago

My bad, I'm so sorry, I wasteed your time, indeed I mistook one node with another, my code does not have the drop dow<n while yours do, so much better !

Very sorry !