-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnodes.py
198 lines (169 loc) · 6.43 KB
/
nodes.py
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
from nodes import KSampler, KSamplerAdvanced, CLIPTextEncode
from .fabric.fabric import fabric_sample, fabric_patch
import torch
import comfy
import warnings
class FABRICPatchModelAdv:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model": ("MODEL",),
"null_pos": ("CONDITIONING",),
"null_neg": ("CONDITIONING",),
"pos_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"neg_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
},
"optional": {
"pos_latents": ("LATENT",),
"neg_latents": ("LATENT",),
}
}
RETURN_TYPES = ("MODEL",)
FUNCTION = "patch"
CATEGORY = "FABRIC"
def patch(self, *args, **kwargs):
return fabric_patch(*args, **kwargs)
class FABRICPatchModel:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"pos_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"neg_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
},
"optional": {
"pos_latents": ("LATENT",),
"neg_latents": ("LATENT",),
}
}
RETURN_TYPES = ("MODEL",)
FUNCTION = "patch"
CATEGORY = "FABRIC"
def patch(self, *args, **kwargs):
clip = kwargs["clip"]
clip_encode = CLIPTextEncode()
null_cond = clip_encode.encode(clip, "")[0]
del kwargs["clip"]
kwargs["null_pos"] = null_cond
kwargs["null_neg"] = null_cond
return fabric_patch(*args, **kwargs)
class KSamplerAdvFABRICAdv:
@classmethod
def INPUT_TYPES(s):
inputs = KSamplerAdvanced.INPUT_TYPES()
added_inputs = {
"required": {
"null_pos": ("CONDITIONING",),
"null_neg": ("CONDITIONING",),
"pos_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"neg_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"feedback_start": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}),
"feedback_end": ("INT", {"default": 10000, "min": 0, "max": 10000, "step": 1}),
},
"optional": {
"pos_latents": ("LATENT",),
"neg_latents": ("LATENT",),
}
}
inputs["required"].update(added_inputs["required"])
if "optional" not in inputs:
inputs["optional"] = {}
inputs["optional"].update(added_inputs["optional"])
return inputs
RETURN_TYPES = ("LATENT",)
FUNCTION = "sample"
CATEGORY = "FABRIC"
def sample(self, *args, **kwargs):
kwargs["denoise"] = 1.0 # Default value
return fabric_sample(*args, **kwargs)
class KSamplerFABRICAdv:
@classmethod
def INPUT_TYPES(s):
inputs = KSampler.INPUT_TYPES()
added_inputs = {
"required": {
"null_pos": ("CONDITIONING",),
"null_neg": ("CONDITIONING",),
"pos_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"neg_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"feedback_start": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}),
"feedback_end": ("INT", {"default": 10000, "min": 0, "max": 10000, "step": 1}),
},
"optional": {
"pos_latents": ("LATENT",),
"neg_latents": ("LATENT",),
}
}
inputs["required"].update(added_inputs["required"])
if "optional" not in inputs:
inputs["optional"] = {}
inputs["optional"].update(added_inputs["optional"])
return inputs
RETURN_TYPES = ("LATENT",)
FUNCTION = "sample"
CATEGORY = "FABRIC"
def sample(self, *args, **kwargs):
"""
Regular KSampler with all FABRIC inputs
"""
# Add default advanced ksampler inputs
kwargs["add_noise"] = False
kwargs["start_at_step"] = None
kwargs["end_at_step"] = None
kwargs["return_with_leftover_noise"] = False
kwargs["noise_seed"] = kwargs.pop("seed")
return fabric_sample(*args, **kwargs)
class KSamplerFABRIC:
@classmethod
def INPUT_TYPES(s):
inputs = KSampler.INPUT_TYPES()
added_inputs = {
"required": {
"clip": ("CLIP",),
"pos_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"neg_weight": ("FLOAT", {"default": 1., "min": 0., "max": 1., "step": 0.01}),
"feedback_percent": ("FLOAT", {"default": 0.8, "min": 0., "max": 1., "step": 0.01}),
},
"optional": {
"pos_latents": ("LATENT",),
"neg_latents": ("LATENT",),
}
}
inputs["required"].update(added_inputs["required"])
if "optional" not in inputs:
inputs["optional"] = {}
inputs["optional"].update(added_inputs["optional"])
return inputs
RETURN_TYPES = ("LATENT",)
FUNCTION = "sample"
CATEGORY = "FABRIC"
def sample(self, *args, **kwargs):
"""
Regular KSampler with intended FABRIC inputs
"""
clip_encode = CLIPTextEncode()
null_cond = clip_encode.encode(kwargs["clip"], "")[0]
del kwargs["clip"]
kwargs["null_pos"] = null_cond
kwargs["null_neg"] = null_cond
# Convert feedback percent to start and end steps
kwargs["feedback_start"] = 0
kwargs["feedback_end"] = int(kwargs["steps"] * kwargs.pop("feedback_percent"))
return KSamplerFABRICAdv().sample(*args, **kwargs)
NODE_CLASS_MAPPINGS = {
"FABRICPatchModelAdv": FABRICPatchModelAdv,
"FABRICPatchModel": FABRICPatchModel,
"KSamplerAdvFABRICAdv": KSamplerAdvFABRICAdv,
"KSamplerFABRICAdv": KSamplerFABRICAdv,
"KSamplerFABRIC": KSamplerFABRIC,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"FABRICPatchModelAdv": "FABRIC Patch Model (Advanced)",
"FABRICPatchModel": "FABRIC Patch Model",
"KSamplerAdvFABRICAdv": "KSampler FABRIC (Advanced)",
"KSamplerFABRICAdv": "KSampler FABRIC",
"KSamplerFABRIC": "KSampler FABRIC (Simple)",
}