-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEmbeddingsNameLoader.py
45 lines (28 loc) · 1.05 KB
/
EmbeddingsNameLoader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import folder_paths
import re
class EmbeddingsNameLoader:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {"required": { "text": ("STRING", {"multiline": True}),
}}
RETURN_TYPES = ("STRING", )
RETURN_NAMES = ("STRING", )
FUNCTION = "run"
CATEGORY = "Embeddings Tools"
def run(self, text):
emb_files = folder_paths.get_filename_list("embeddings")
output_text = text
for file_name in emb_files:
base_name = file_name.split('\\')[-1].split('.')[0]
#output_text = output_text.replace(base_name, f"embedding:{base_name}")
pattern = re.compile(re.escape(base_name), re.IGNORECASE)
output_text = pattern.sub(f"embedding:{base_name}", output_text)
return (output_text, )
NODE_CLASS_MAPPINGS = {
"EmbeddingsNameLoader": EmbeddingsNameLoader,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"EmbeddingsNameLoader": "Load Embeddings by Name",
}