shiimizu / ComfyUI_smZNodes

Custom nodes for ComfyUI such as CLIP Text Encode++
GNU General Public License v3.0
168 stars 12 forks source link

Embeddings Parsing Error with Backslashes in Prompt Parser (Mode A1111) #70

Closed drozbay closed 2 months ago

drozbay commented 2 months ago

Issue Description: When using parsing mode A1111 in the text encoder prompt parser, backslashes () used in Windows directory paths for embeddings are misinterpreted or removed, leading to unrecognized embeddings. The problem is traced back to prompt_parser.py in parse_prompt_attention() where backslashes are removed regardless of if they are part of an embedding directory structure or not:

        if text.startswith('\\'):
            res.append([text[1:], 1.0])

This results in the non-application of embeddings, even though the embeddings with backslash characters are correctly registered in parse_and_register_embeddings.

There are common extensions, specifically the custom-scripts extension from pythongosssss, that allow for quick adding of embedding text, but in Windows at least it uses the backslash character for the directory structure. This means that a bunch of people using both extensions may not be actually applying the embeddings even though it seems like they are.

Proposed possible fix: I tried adding this code, which just makes sure that there are no backslash characters in an embedding directory name after being parsed as a valid embedding. Seems to work with my testing.

In parse_and_register_embeddings, in file smZNodes.py:

for matchNum, match in enumerate(matches, start=1):
    ext = ext if (ext:=match.group(4)) else ''
    embedding_sname = embedding_sname if (embedding_sname:=match.group(2)) else ''
    if '\\' in embedding_sname:
        embedding_sname = embedding_sname.replace('\\', '/')
        text = text.replace('\\', '/')
    embedding_name = embedding_sname + ext
drozbay commented 2 months ago

Thank you for acknowledging and working to fix this issue. I tried the latest commit and am still seeing this problem: image

shiimizu commented 2 months ago

Thanks for pointing that out. https://github.com/shiimizu/ComfyUI_smZNodes/commit/c91ab1a9568ffb17ffdc8c2932be47ee68205490 was to fix inputting embeddings with brackets in their filename like emb_\(test\). https://github.com/shiimizu/ComfyUI_smZNodes/commit/a1627ce2ade31822694d82aa9600a4eff0f99d69 should fix your issue now.

drozbay commented 2 months ago

Thank you for fixing this issue, it is working perfectly now!