WASasquatch / was-node-suite-comfyui

An extensive node suite for ComfyUI with over 210 new nodes
MIT License
1.15k stars 170 forks source link

Text Parse A1111 Embeddings is adding 'embedding:' twice #249

Open drphero opened 11 months ago

drphero commented 11 months ago

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.

WASasquatch commented 11 months ago

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

drphero commented 11 months ago

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

cjps-br commented 9 months ago

@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
WASasquatch commented 9 months ago

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: @.***>