File size: 14,298 Bytes
edb09f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
import math, cv2, random, torch, torchvision, json, os
import numpy as np
import nodes, folder_paths  # ๊ธฐ๋ณธ๋…ธ๋“œ, ํŒŒ์ผ๋กœ๋“œ
from . import wildcards
from .utils import any_typ
from server import PromptServer
from . import utils

if os.path.isfile("./custom_nodes/image_control/prompts_maker.py"):
    from . import prompts_maker
    from openpyxl import load_workbook
    from openpyxl.styles import Alignment

# class name:
#     def __init__(self):
#         pass

#     @classmethod
#     def INPUT_TYPES(s):
#         return {
#         "required": {},
#         "optional": {},
#         }
#     RETURN_TYPES = ()
#     RETURN_NAMES = ()

#     FUNCTION = "run"

#     CATEGORY = "abyz22"

#     def run(sefl,*args,**kwargs):
#         return None


class abyz22_setimageinfo:
    def __init__(self):
        pass

    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "mode_type": (["ab", "d"],),
                "Num of Prompts": ("INT", {"default": 1, "min": 0, "max": 30, "step": 1}),
                "image per Prompt": ("INT", {"default": 1, "min": 1, "max": 100, "step": 1}),
                "batch_size": ("INT", {"default": 1, "min": 1, "max": 10, "step": 1}),
                "width": ("INT", {"default": 512, "min": 64, "max": 2048, "step": 64}),
                "height": ("INT", {"default": 768, "min": 64, "max": 2048, "step": 64}),
            },
        }

    RETURN_TYPES = ("STRING", "INT", "INT", "INT", "INT", "INT")
    RETURN_NAMES = ("Mode_type", "Num of Prompts", "image per Prompt", "batch_size", "width", "height")

    FUNCTION = "run"

    CATEGORY = "abyz22"

    def run(sefl, *args, **kwargs):
        return (
            kwargs["mode_type"],
            kwargs["Num of Prompts"],
            kwargs["image per Prompt"],
            kwargs["batch_size"],
            kwargs["width"],
            kwargs["height"],
        )


class abyz22_ImpactWildcardEncode_GetPrompt:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "model": ("MODEL",),
                "clip": ("CLIP",),
                "wildcard_text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
                "mode": ("BOOLEAN", {"default": True, "label_on": "Populate", "label_off": "Fixed"}),
                "Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
                "Select to add Wildcard": (["Select the Wildcard to add to the text"],),
                "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}),
            },
        }

    CATEGORY = "abyz22"

    RETURN_TYPES = ("MODEL", "CLIP", "CONDITIONING", "STRING")
    RETURN_NAMES = ("model", "clip", "conditioning", "populated_text")
    FUNCTION = "doit"

    @staticmethod
    def process_with_loras(**kwargs):
        return wildcards.process_with_loras(**kwargs)

    @staticmethod
    def get_wildcard_list():  # ์ด๊ฑด ์‚ฌ์šฉ ์•ˆํ•จ (์™œ์žˆ๋Š”์ง€ ๋ชจ๋ฆ„)
        return wildcards.get_wildcard_list()

    def doit(self, *args, **kwargs):
        wildcard_process = nodes.NODE_CLASS_MAPPINGS["ImpactWildcardProcessor"].process

        populated = wildcard_process(text=kwargs["wildcard_text"], seed=kwargs["seed"])
        model, clip, conditioning = wildcards.process_with_loras(populated, kwargs["model"], kwargs["clip"])

        return (model, clip, conditioning, populated)


class abyz22_SetQueue:
    def __init__(self):
        self.cur_prompts, self.cur_batch = 0, 0
        self.highest_num = 0
        self.base_folder_path = ""
        self.prompt = ""
        self.debug = ""

    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "mode_type": ("STRING", {"default": "ab"}),
                "Num_of_Prompts": ("INT", {"default": 1, "min": 0, "max": 30, "step": 1}),
                "image_per_Prompt": ("INT", {"default": 24, "min": 1, "max": 30, "step": 1}),
                "batch_size": ("INT", {"default": 1, "min": 1, "max": 30, "step": 1}),
                "seed": ("INT", {"default": 1, "min": 1, "max": 0xFFFFFFFFFFFFFFFF}),
                "prompt": ("STRING", {"multiline": True}),
            },
        }

    RETURN_TYPES = ("BOOLEAN", "STRING", "STRING", "INT", "INT", "STRING")
    RETURN_NAMES = ("Bool_trigger_queue", "folder_path", "prompt", "cur_prompts", "cur_batch", "debug")

    FUNCTION = "run"

    CATEGORY = "abyz22"

    def run(self, *args, **kwargs):
        cur_prompts, cur_batch = self.cur_prompts, self.cur_batch
        Bool_trigger_queue = False

        new_path = "no-data"

        if kwargs["Num_of_Prompts"] != 0:  # ํด๋”์ƒ์„ฑ 1 ์ด์ƒ์ด๋ฉด
            if self.highest_num == 0:  # ์ตœ๊ณ ํด๋” ๋ฒˆํ˜ธ ๊ธฐ๋ณธ๊ฐ’=0 ์œผ๋กœ ๋˜์žˆ์œผ๋ฉด, ์ตœ๊ณ ํด๋” ์ฐพ๊ธฐ
                if kwargs["mode_type"] == "ab":
                    self.base_folder_path = "E:/ComfyUI/output/submit1/"
                elif kwargs["mode_type"] == "d":
                    self.base_folder_path = "E:/ComfyUI/output/submit3/"
                file_list = os.listdir(self.base_folder_path)
                file_list = [f for f in file_list if len(f.split(".")) == 1]
                file_list = [int(f.split(" ")[0]) for f in file_list]
                file_list.sort(reverse=True)
                self.highest_num = file_list[0] + 1

            if self.cur_batch == 0:  # ๋Œ๊ณ ๋Œ์•„ ํ˜„์žฌ ํด๋” ๋ฐฐ์น˜0๋˜๋ฉด(์ฒ˜์Œ)
                if (kwargs["Num_of_Prompts"] == 1) and (kwargs["prompt"] != ""):  # ํด๋”1๊ฐœ๋งŒ์ด๊ณ  ํ”„๋กฌํ”„ํŠธ ์žˆ์œผ๋ฉด,
                    self.prompt = kwargs["prompt"]
                else:
                    self.prompt = prompts_maker.make_prompt(
                        mode=kwargs["mode_type"], etc=self.highest_num + 1 + self.cur_prompts, seed=kwargs["seed"]
                    )

                epath = "E:/ComfyUI/output/history.xlsx"
                T_workbook = load_workbook(epath, data_only=True)
                if kwargs["mode_type"] == "ab":
                    T_worksheet = T_workbook["Sheet1,2"]
                elif kwargs["mode_type"] == "d":
                    T_worksheet = T_workbook["Sheet4"]

                # find excel-index
                # new_idx = 0
                # for i in range(100, 9999):
                #     if T_worksheet[f"E{i}"].value == None:
                #         new_idx = i
                #         break
                # if new_idx == (self.highest_num + self.cur_prompts + 4):
                #     T_worksheet[f"E{new_idx}"].value = self.prompt
                # else:
                #     raise Exception("excel idx doesn't match")
                new_idx = self.highest_num + self.cur_prompts + 4

                T_worksheet[f"E{new_idx}"].value = self.prompt
                T_worksheet.row_dimensions[new_idx].height = 48
                T_worksheet[f"E{new_idx}"].alignment = Alignment(wrap_text=True)
                T_workbook.save(epath)

            new_path = self.base_folder_path + str(self.highest_num + self.cur_prompts)

        if kwargs["Num_of_Prompts"] == 0:
            Bool_trigger_queue = False
            cur_prompts, cur_batch = 0, 0
            self.highest_num, self.prompt = 0, ""
            self.debug = "Prompt testing...."

        elif cur_prompts < kwargs["Num_of_Prompts"]:  # ํด๋” ๋ณ„
            if (cur_batch + kwargs["batch_size"]) < kwargs["image_per_Prompt"]:  # ํด๋”๋‚ด ์ƒ์„ฑํ•ด์•ผ๋  ์ด๋ฏธ์ง€ ๋” ์žˆ์œผ๋ฉด
                Bool_trigger_queue = True
                cur_prompts, cur_batch = cur_prompts, cur_batch + kwargs["batch_size"]
                self.debug = f"{cur_prompts} / {cur_batch}"

            else:  # ํด๋” ๋‚ด ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋๋‚˜๋ฉด(ํด๋” ๋‚ด ๋งˆ์ง€๋ง‰ ํ‹ฑ)
                if (cur_prompts + 1) >= kwargs["Num_of_Prompts"]:  # ๋งˆ์ง€๋ง‰ ํด๋”์ผ๋•Œ
                    Bool_trigger_queue = False
                    cur_prompts, cur_batch = 0, 0
                    self.highest_num = 0
                    self.debug = "4444444"
                else:  # ์ƒ์„ฑํ•ด์•ผํ•  ํด๋” ๋‚จ์•„์žˆ์œผ๋ฉด
                    Bool_trigger_queue = True
                    cur_prompts, cur_batch = cur_prompts + 1, 0
                    self.debug = "55555"

        self.cur_prompts, self.cur_batch = cur_prompts, cur_batch
        return Bool_trigger_queue, new_path, self.prompt, cur_prompts, cur_batch, self.debug


def workflow_to_map(workflow):
    nodes = {}
    links = {}
    for link in workflow["links"]:
        links[link[0]] = link[1:]
    for node in workflow["nodes"]:
        nodes[str(node["id"])] = node

    return nodes, links


class abyz22_bypass:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "value": (any_typ,),
                "mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Mute/Bypass"}),
                "behavior": ("BOOLEAN", {"default": True, "label_on": "Mute", "label_off": "Bypass"}),
                "prob": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01, "round": 0.001, "dispaly": "slider"}),
            },
            "hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
        }

    FUNCTION = "doit"

    RETURN_TYPES = (any_typ,)
    RETURN_NAMES = ("value",)
    OUTPUT_NODE = True
    CATEGORY = "abyz22"

    @classmethod
    def IS_CHANGED(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
        nodes, links = workflow_to_map(extra_pnginfo["workflow"])

        next_nodes = []

        for link in nodes[unique_id]["outputs"][0]["links"]:
            node_id = str(links[link][2])
            utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)

        return next_nodes

    def doit(self, value, mode, behavior=True, prob=0.5, unique_id=None, prompt=None, extra_pnginfo=None):
        global error_skip_flag

        nodes, links = workflow_to_map(extra_pnginfo["workflow"])

        active_nodes = []
        mute_nodes = []
        bypass_nodes = []

        for link in nodes[unique_id]["outputs"][0]["links"]:
            node_id = str(links[link][2])

            next_nodes = []
            utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)

            for next_node_id in next_nodes:
                node_mode = nodes[next_node_id]["mode"]

                if node_mode == 0:
                    active_nodes.append(next_node_id)
                elif node_mode == 2:
                    mute_nodes.append(next_node_id)
                elif node_mode == 4:
                    bypass_nodes.append(next_node_id)

        if (mode == False) and (random.random() < prob):
            if behavior:  # mute
                should_be_mute_nodes = active_nodes + bypass_nodes
                if len(should_be_mute_nodes) > 0:
                    PromptServer.instance.send_sync(
                        "impact-bridge-continue", {"node_id": unique_id, "mutes": list(should_be_mute_nodes)}
                    )
                    error_skip_flag = True
                    raise Exception(
                        "IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."
                    )
            else:  # bypass
                should_be_bypass_nodes = active_nodes + mute_nodes
                if len(should_be_bypass_nodes) > 0:
                    PromptServer.instance.send_sync(
                        "impact-bridge-continue", {"node_id": unique_id, "bypasses": list(should_be_bypass_nodes)}
                    )
                    error_skip_flag = True
                    raise Exception(
                        "IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."
                    )
        else:
            # active
            should_be_active_nodes = mute_nodes + bypass_nodes
            if len(should_be_active_nodes) > 0:
                PromptServer.instance.send_sync(
                    "impact-bridge-continue", {"node_id": unique_id, "actives": list(should_be_active_nodes)}
                )
                error_skip_flag = True
                raise Exception(
                    "IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."
                )

        # if mode:
        #     # active
        #     should_be_active_nodes = mute_nodes + bypass_nodes
        #     if len(should_be_active_nodes) > 0:
        #         PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_be_active_nodes)})
        #         error_skip_flag = True
        #         raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")

        # elif behavior:
        #     # mute
        #     should_be_mute_nodes = active_nodes + bypass_nodes
        #     if len(should_be_mute_nodes) > 0:
        #         PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_be_mute_nodes)})
        #         error_skip_flag = True
        #         raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")

        # else:
        #     # bypass
        #     should_be_bypass_nodes = active_nodes + mute_nodes
        #     if len(should_be_bypass_nodes) > 0:
        #         PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'bypasses': list(should_be_bypass_nodes)})
        #         error_skip_flag = True
        #         raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")

        return (value,)