EQX55 commited on
Commit
b45b9a5
verified
1 Parent(s): 88a904f

Upload comfy_register_nodes.py

Browse files
Files changed (1) hide show
  1. comfy_register_nodes.py +58 -0
comfy_register_nodes.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+
4
+ class LoadPromptFromFileEQXNode:
5
+ @classmethod
6
+ def INPUT_TYPES(cls):
7
+ return {
8
+ "required": {
9
+ "file_path": ("STRING", {"default": "", "multiline": False}),
10
+ "seed": ("INT", {"default": 0, "min": 0, "max": 10000000}),
11
+ }
12
+ }
13
+
14
+ RETURN_TYPES = ("STRING", "STRING", "STRING", "INT")
15
+ RETURN_NAMES = ("id", "prompt", "negative_prompt", "seed")
16
+ FUNCTION = "load_prompt"
17
+ CATEGORY = "Load"
18
+
19
+ def load_prompt(self, file_path, seed):
20
+ # Si no existe el fichero, devolvemos vac铆os
21
+ if not os.path.isfile(file_path):
22
+ return "", "", "", seed
23
+
24
+ prompt_list = []
25
+ # Leemos l铆nea a l铆nea y extraemos ID, prompt positivo y negativo
26
+ with open(file_path, 'r', encoding='utf-8') as file:
27
+ for raw_line in file:
28
+ line = raw_line.strip()
29
+ # Eliminamos coma final si existe
30
+ if line.endswith(','):
31
+ line = line[:-1]
32
+ # Pattern: {{{ID}}}{{positive}}{{negative}}
33
+ m = re.match(r"\{\{\{([^}]*)\}\}\}\{\{([^}]*)\}\}\{([^}]*)\}", line)
34
+ if m:
35
+ identificador, positive, negative = m.groups()
36
+ prompt_list.append((identificador.strip(), positive.strip(), negative.strip()))
37
+
38
+ if not prompt_list:
39
+ return "", "", "", seed
40
+
41
+ # Selecci贸n basada en seed
42
+ index = seed % len(prompt_list)
43
+ identificador, positive, negative = prompt_list[index]
44
+ seed += 1
45
+ return (
46
+ identificador,
47
+ positive,
48
+ negative,
49
+ seed
50
+ )
51
+
52
+ NODE_CLASS_MAPPINGS = {
53
+ "Load Prompt From File - EQX": LoadPromptFromFileEQXNode
54
+ }
55
+
56
+ NODE_DISPLAY_NAME_MAPPINGS = {
57
+ "Load Prompt From File - EQX": "Load Prompt From File - EQX"
58
+ }