was-node-suite-comfyui icon indicating copy to clipboard operation
was-node-suite-comfyui copied to clipboard

Text Parse A1111 Embeddings is adding 'embedding:' twice

Open drphero opened this issue 2 years ago • 4 comments

I used the 'Show Text' node from pythongosssss to see the output of the 'Text Parse A1111 Embeddings' node and 'embedding:' is getting added twice. So 'bad-hands-5' becomes 'embedding:embedding:bad-hands-5'. The 'Text to Console' node shows the same thing.

drphero avatar Oct 24 '23 09:10 drphero

Well that's not good. I'll take a look, thanks for pointing that out.

WASasquatch avatar Oct 24 '23 21:10 WASasquatch

@WASasquatch Just noticed that it sometimes will add it four times, like "embedding:embedding:embedding:embedding:bad-artist-anime"

drphero avatar Oct 30 '23 23:10 drphero

@WASasquatch I also noticed the problem with multiple embeddings, and realized that the problem is if there are additional files (such as jpg and Json) with the same name as embeddings.pt. I use the same template directory structure for both the SD.NEXT interface and comfyui and the SD.NEXT manager attaches jpeg and json files alongside the pt files.

Furthermore, my embeddings files are placed in subdirectories of the main directory. Then I noticed that the parse node is unable to evaluate the files that are in the subdirectories.

I also noticed that the node function uses a function called convert_a1111_embeddings. So, in my installation, I did a test making a change to the function and I think it solved both problems. I leave here the suggested change for evaluation:

 def convert_a1111_embeddings(self, text):
     # for embeddings_path in comfy_paths.folder_names_and_paths["embeddings"][0]:
     # for filename in os.listdir(embeddings_path):
     # basename, ext = os.path.splitext(filename)
     # pattern = re.compile(r'\b{}\b'.format(re.escape(basename)))
     # replacement = 'embedding:{}'.format(basename)
     # text = re.sub(pattern, replacement, text)
     #
     # return text
     for embeddings_path in comfy_paths.folder_names_and_paths["embeddings"][0]:
         for root, dirs, files in os.walk(embeddings_path):
             for filename in files:
                 basename, ext = os.path.splitext(filename)
                 if ext in comfy_paths.supported_pt_extensions:
                     pattern = re.compile(r'\b{}\b'.format(re.escape(basename)))
                     replacement = 'embedding:{}'.format(basename)
                     text = re.sub(pattern, replacement, text)
     return text

cjps-br avatar Dec 12 '23 21:12 cjps-br

You can make a PR if you want. Though to node it may be necessary to also loop through the folder_paths embedding list as it may have "extra" embeddings paths added outside models dir

On Tue, Dec 12, 2023, 1:20 PM cjps-br @.***> wrote:

@WASasquatch https://github.com/WASasquatch I also noticed the problem with multiple embeddings, and realized that the problem is if there are additional files (such as jpg and Json) with the same name as embeddings.pt. I use the same template directory structure for both the SD.NEXT interface and comfyui and the SD.NEXT manager attaches jpeg and json files alongside the pt files.

Furthermore, my embeddings files are placed in subdirectories of the main directory. Then I noticed that the parse node is unable to evaluate the files that are in the subdirectories.

I also noticed that the node function uses a function called convert_a1111_embeddings. So, in my installation, I did a test making a change to the function and I think it solved both problems. I leave here the suggested change for evaluation:

def convert_a1111_embeddings(self, text): # for embeddings_path in comfy_paths.folder_names_and_paths["embeddings"][0]: # for filename in os.listdir(embeddings_path): # basename, ext = os.path.splitext(filename) # pattern = re.compile(r'\b{}\b'.format(re.escape(basename))) # replacement = 'embedding:{}'.format(basename) # text = re.sub(pattern, replacement, text) # # return text for embeddings_path in comfy_paths.folder_names_and_paths["embeddings"][0]: print(text) for root, dirs, files in os.walk(embeddings_path): for filename in files: basename, ext = os.path.splitext(filename) if ext in comfy_paths.supported_pt_extensions: pattern = re.compile(r'\b{}\b'.format(re.escape(basename))) replacement = 'embedding:{}'.format(basename) text = re.sub(pattern, replacement, text) return text

— Reply to this email directly, view it on GitHub https://github.com/WASasquatch/was-node-suite-comfyui/issues/249#issuecomment-1852828034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIZEZK33564VXVP3F4EK3DYJDDA5AVCNFSM6AAAAAA6NMTKMKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJSHAZDQMBTGQ . You are receiving this because you were mentioned.Message ID: @.***>

WASasquatch avatar Dec 18 '23 20:12 WASasquatch