File size: 4,307 Bytes
baa8e90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import random

from .utils import *

class FusionText:
    @classmethod
    def INPUT_TYPES(s):
        return {"required": {"text_1": ("STRING", {"default": "", "forceInput": True}), "text_2": ("STRING", {"default": "", "forceInput": True})}}
    RETURN_TYPES = ("STRING",)
    FUNCTION = "combine"
    CATEGORY = "autotrigger"

    def combine(self, text_1, text_2):
        return (text_1 + text_2, )


class Randomizer:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
               "text_1":("STRING", {"forceInput": True}), 
               "lora_1":("LORA_STACK", ), 
               "text_2":("STRING", {"forceInput": True} ), 
               "lora_2":("LORA_STACK", ), 
               "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
            },
        }

    RETURN_TYPES = ("STRING", "LORA_STACK")
    RETURN_NAMES = ("text", "lora stack")
    FUNCTION = "randomize"

    #OUTPUT_NODE = False

    CATEGORY = "autotrigger"

    def randomize(self, text_1, lora_1, text_2, lora_2, seed):
        random.seed(seed)
        if random.random() < .5:
            return (text_1, lora_1)
        return (text_2, lora_2)
    
class TextInputBasic:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
               "text":("STRING", {"default":"", "multiline":True}), 
            },
            "optional": {
                "prefix":("STRING", {"default":"", "forceInput": True}), 
                "suffix":("STRING", {"default":"", "forceInput": True}), 
            }
        }

    RETURN_TYPES = ("STRING",)
    RETURN_NAMES = ("text", )
    FUNCTION = "get_text"

    #OUTPUT_NODE = False

    CATEGORY = "autotrigger"

    def get_text(self, text, prefix="", suffix=""):
        return (prefix + text + suffix, )
    

class TagsSelector:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": { 
                "tags_list": ("LIST", {"default": []}),
                "selector": ("STRING", {"default": ":"}),
                "weight": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
                "ensure_comma": ("BOOLEAN", {"default": True})
            },
            "optional": {
                "prefix":("STRING", {"default":"", "forceInput": True}), 
                "suffix":("STRING", {"default":"", "forceInput": True}), 
            }
        }
    
    RETURN_TYPES = ("STRING",)
    FUNCTION = "select_tags"
    CATEGORY = "autotrigger"

    def select_tags(self, tags_list, selector, weight, ensure_comma, prefix="", suffix=""):
        if weight != 1.0:
            tags_list = [f"({tag}:{weight})" for tag in tags_list]
        output = parse_selector(selector, tags_list)
        if ensure_comma:
            striped_prefix = prefix.strip()
            striped_suffix = suffix.strip()
            if striped_prefix != "" and not striped_prefix.endswith(",") and output != "" and not output.startswith(","):
                prefix = striped_prefix + ", "
            if output != "" and not output.endswith(",") and striped_suffix != "" and not striped_suffix.startswith(","):
                suffix = ", " + striped_suffix
        return (prefix + output + suffix, )

class TagsFormater:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": { 
                "tags_list": ("LIST", {"default": []}),
            },
        }
    
    RETURN_TYPES = ("STRING",)
    FUNCTION = "format_tags"
    CATEGORY = "autotrigger"

    def format_tags(self, tags_list):
        output = ""
        i = 0
        for tag in tags_list:
            output += f'{i} : "{tag}"\n'
            i+=1

        return (output,)

# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
    "Randomizer": Randomizer,
    "FusionText": FusionText,
    "TextInputBasic": TextInputBasic,
    "TagsSelector": TagsSelector,
    "TagsFormater": TagsFormater,
}

# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
    "Randomizer": "Randomizer",
    "FusionText": "FusionText",
    "TextInputBasic": "TextInputBasic",
    "TagsSelector": "TagsSelector",
    "TagsFormater": "TagsFormater",
}