Spaces:
Running
Running
File size: 8,611 Bytes
613c9ab |
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 |
class StringConcatenate:
def __init__(self):
pass
defaultPrompt = """"0" :"",
"12" :"",
"24" :"",
"36" :"",
"48" :"",
"60" :"",
"72" :"",
"84" :"",
"96" :"",
"108" :"",
"120" :""
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text_a": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_a": ("INT", {"default": 0}),
"text_b": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_b": ("INT", {"default": 12})
},
"optional": {
"text_c": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_c": ("INT", {"default": 24}),
"text_d": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_d": ("INT", {"default": 36}),
"text_e": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_e": ("INT", {"default": 48}),
"text_f": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_f": ("INT", {"default": 60}),
"text_g": ("STRING", {"forceInput": True, "multiline": True, "default": ""}),
"frame_g": ("INT", {"default": 72})
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "frame_concatenate_list"
CATEGORY = "FizzNodes π
π
π
/FrameNodes"
def frame_concatenate_list(self, text_a, frame_a, text_b, frame_b, text_c=None, frame_c=None, text_d=None,
frame_d=None, text_e=None, frame_e=None, text_f=None, frame_f=None, text_g=None,
frame_g=None):
text_a = text_a.replace('\n', '')
text_b = text_b.replace('\n', '')
text_c = text_c.replace('\n', '') if text_c is not None else None
text_d = text_d.replace('\n', '') if text_d is not None else None
text_e = text_e.replace('\n', '') if text_e is not None else None
text_f = text_f.replace('\n', '') if text_f is not None else None
text_g = text_g.replace('\n', '') if text_g is not None else None
text_list = f'"{frame_a}": "{text_a}",'
text_list += f'"{frame_b}": "{text_b}",'
if frame_c is not None and text_c is not None:
text_list += f'"{frame_c}": "{text_c}",'
if frame_d is not None and text_d is not None:
text_list += f'"{frame_d}": "{text_d}",'
if frame_e is not None and text_e is not None:
text_list += f'"{frame_e}": "{text_e}",'
if frame_f is not None and text_f is not None:
text_list += f'"{frame_f}": "{text_f}",'
if frame_g is not None and text_g is not None:
text_list += f'"{frame_g}": "{text_g}",'
return (text_list,)
class InitNodeFrame:
def __init__(self):
self.frames = {}
self.thisFrame = {}
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"frame": ("INT", {"default": 0, "min": 0}),
"positive_text": ("STRING", {"multiline": True}),
},
"optional": {
"negative_text": ("STRING", {"multiline": True}),
"general_positive": ("STRING", {"multiline": True}),
"general_negative": ("STRING", {"multiline": True}),
"previous_frame": ("FIZZFRAME", {"forceInput": True}),
"clip": ("CLIP",),
}
}
RETURN_TYPES = ("FIZZFRAME","CONDITIONING","CONDITIONING",)
FUNCTION = "create_frame"
CATEGORY = "FizzNodes π
π
π
/FrameNodes"
def create_frame(self, frame, positive_text, negative_text=None, general_positive=None, general_negative=None, previous_frame=None, clip=None):
new_frame = {
"positive_text": positive_text,
"negative_text": negative_text,
}
if previous_frame:
prev_frame = previous_frame.thisFrame
new_frame["general_positive"] = prev_frame["general_positive"]
new_frame["general_negative"] = prev_frame["general_negative"]
new_frame["clip"] = prev_frame["clip"]
self.frames = previous_frame.frames
if general_positive:
new_frame["general_positive"] = general_positive
if general_negative:
new_frame["general_negative"] = general_negative
new_positive_text = f"{positive_text}, {new_frame['general_positive']}"
new_negative_text = f"{negative_text}, {new_frame['general_negative']}"
if clip:
new_frame["clip"] = clip
pos_tokens = new_frame["clip"].tokenize(new_positive_text)
pos_cond, pos_pooled = new_frame["clip"].encode_from_tokens(pos_tokens, return_pooled=True)
new_frame["pos_conditioning"] = {"cond": pos_cond, "pooled": pos_pooled}
neg_tokens = new_frame["clip"].tokenize(new_negative_text)
neg_cond, neg_pooled = new_frame["clip"].encode_from_tokens(neg_tokens, return_pooled=True)
new_frame["neg_conditioning"] = {"cond": neg_cond, "pooled": neg_pooled}
self.frames[frame] = new_frame
self.thisFrame = new_frame
return (self, [[pos_cond, {"pooled_output": pos_pooled}]], [[neg_cond, {"pooled_output": neg_pooled}]])
class NodeFrame:
def __init__(self):
self.frames = {}
self.thisFrame = {}
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"frame": ("INT", {"default": 0, "min": 0}),
"previous_frame": ("FIZZFRAME", {"forceInput": True}),
"positive_text": ("STRING", {"multiline": True}),
},
"optional": {
"negative_text": ("STRING", {"multiline": True}),
}
}
RETURN_TYPES = ("FIZZFRAME","CONDITIONING","CONDITIONING",)
FUNCTION = "create_frame"
CATEGORY = "FizzNodes π
π
π
/FrameNodes"
def create_frame(self, frame, previous_frame, positive_text, negative_text=None):
self.frames = previous_frame.frames
prev_frame = previous_frame.thisFrame
new_positive_text = f"{positive_text}, {prev_frame['general_positive']}"
new_negative_text = f"{negative_text}, {prev_frame['general_negative']}"
pos_tokens = prev_frame["clip"].tokenize(new_positive_text)
pos_cond, pos_pooled = prev_frame["clip"].encode_from_tokens(pos_tokens, return_pooled=True)
neg_tokens = prev_frame["clip"].tokenize(new_negative_text)
neg_cond, neg_pooled = prev_frame["clip"].encode_from_tokens(neg_tokens, return_pooled=True)
new_frame = {
"positive_text": positive_text,
"negative_text": negative_text,
"general_positive": prev_frame["general_positive"],
"general_negative": prev_frame["general_negative"],
"clip": prev_frame["clip"],
"pos_conditioning": {"cond": pos_cond, "pooled": pos_pooled},
"neg_conditioning": {"cond": neg_cond, "pooled": neg_pooled},
}
self.thisFrame = new_frame
self.frames[frame] = new_frame
return (self, [[pos_cond, {"pooled_output": pos_pooled}]], [[neg_cond, {"pooled_output": neg_pooled}]])
class FrameConcatenate:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"frame": ("FIZZFRAME", {"forceInput": True})
},
}
RETURN_TYPES = ("STRING",)
FUNCTION = "frame_concatenate"
CATEGORY = "FizzNodes π
π
π
/FrameNodes"
def frame_concatenate(self, frame):
text_list = ""
for frame_digit in frame.frames:
new_frame = frame.frames[frame_digit]
text_list += f'"{frame_digit}": "{new_frame["positive_text"]}'
if new_frame.get("general_positive"):
text_list += f', {new_frame["general_positive"]}'
if new_frame.get("negative_text") or new_frame.get("general_negative"):
text_list += f', --neg '
if new_frame.get("negative_text"):
text_list += f', {new_frame["negative_text"]}'
if new_frame.get("general_negative"):
text_list += f', {new_frame["general_negative"]}'
text_list += f'",\n'
text_list = text_list[:-2]
return (text_list,) |