File size: 1,947 Bytes
b45b9a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import re

class LoadPromptFromFileEQXNode:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "file_path": ("STRING", {"default": "", "multiline": False}),
                "seed": ("INT", {"default": 0, "min": 0, "max": 10000000}),
            }
        }

    RETURN_TYPES = ("STRING", "STRING", "STRING", "INT")
    RETURN_NAMES = ("id", "prompt", "negative_prompt", "seed")
    FUNCTION = "load_prompt"
    CATEGORY = "Load"

    def load_prompt(self, file_path, seed):
        # Si no existe el fichero, devolvemos vacíos
        if not os.path.isfile(file_path):
            return "", "", "", seed

        prompt_list = []
        # Leemos línea a línea y extraemos ID, prompt positivo y negativo
        with open(file_path, 'r', encoding='utf-8') as file:
            for raw_line in file:
                line = raw_line.strip()
                # Eliminamos coma final si existe
                if line.endswith(','):
                    line = line[:-1]
                # Pattern: {{{ID}}}{{positive}}{{negative}}
                m = re.match(r"\{\{\{([^}]*)\}\}\}\{\{([^}]*)\}\}\{([^}]*)\}", line)
                if m:
                    identificador, positive, negative = m.groups()
                    prompt_list.append((identificador.strip(), positive.strip(), negative.strip()))

        if not prompt_list:
            return "", "", "", seed

        # Selección basada en seed
        index = seed % len(prompt_list)
        identificador, positive, negative = prompt_list[index]
        seed += 1
        return (
            identificador,
            positive,
            negative,
            seed
        )

NODE_CLASS_MAPPINGS = {
    "Load Prompt From File - EQX": LoadPromptFromFileEQXNode
}

NODE_DISPLAY_NAME_MAPPINGS = {
    "Load Prompt From File - EQX": "Load Prompt From File - EQX"
}