This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
179 lines (140 loc) · 4.45 KB
/
util.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
import math
import whratio
from .base import GLOBAL_CATEGORY, BaseNode
# noinspection PyUnresolvedReferences,PyPackageRequirements
import comfy
# noinspection PyUnresolvedReferences,PyPackageRequirements
import comfy.samplers
# noinspection PyUnresolvedReferences,PyPackageRequirements
from nodes import MAX_RESOLUTION
MODULE_CATEGORY = f"{GLOBAL_CATEGORY}/util"
class HelperNodes_WidthHeight(BaseNode):
"""
Simple integer values node that allows definition of the
image height and width for passing into empty latents
as Integers.
Permits custom values between 8 and 4096, in steps of 8.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"width": ("INT", {
"default": 1024,
"min": 8,
"max": MAX_RESOLUTION,
"step": 8,
"display": "number"
}),
"height": ("INT", {
"default": 1024,
"min": 8,
"max": MAX_RESOLUTION,
"step": 8,
"display": "number"
}),
}
}
RETURN_TYPES = ("INT", "INT", "STRING", "STRING",)
RETURN_NAMES = ("width", "height", "aspect ratio", "orientation",)
CATEGORY = f"{MODULE_CATEGORY}"
FUNCTION = "process"
def process(self, width, height):
if width > height:
orientation = "landscape"
elif width < height:
orientation = "portrait"
else:
orientation = "square"
aspect = whratio.as_int(width, height)
aspect_ratio = f"{aspect[0]}:{aspect[1]}"
return width, height, aspect_ratio, orientation
class HelperNodes_CfgScale(BaseNode):
"""
Simple integer value node that allows you to specify the CFG scale
for how strictly to the prompt the AI is.
Permits values between 0 and 10, defaults at 8.0, and permits
revisions as small as 0.25 on CFG scale selection. Rounds to two
decimal points.
"""
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
"required": {
"scale": ("FLOAT", {
"default": 8.00,
"min": 0.00,
"max": 10.00,
"step": 0.25,
"round": 0.00,
"display": "number"
}),
}
}
RETURN_TYPES = ("FLOAT", )
RETURN_NAMES = ("CFG",)
CATEGORY = f"{MODULE_CATEGORY}"
FUNCTION = "process"
def process(self, scale) -> tuple:
return (scale,)
class HelperNodes_Steps(BaseNode):
"""
Simple integer value node that allows you to specify the number of
sample steps to make in KSampler.
Permits you to select between 1 and 100, but defaults at 25.
"""
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
"required": {
"steps": ("INT", {
"default": 25,
"min": 1,
"max": 100,
"step": 1,
"display": "number"
}),
}
}
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("steps",)
CATEGORY = f"{MODULE_CATEGORY}"
def process(self, steps) -> tuple:
return (steps,)
class HelperNodes_StringLiteral(BaseNode):
"""
Simple String value node that allows you to specify a string to pass
into other nodes.
Does not permit multiline text. See HelperNodes_MultilineStringLiteral
for multiline text values.
"""
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
"required": {
"string": ("STRING", {"multiline": False})
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("STRING",)
CATEGORY = f"{MODULE_CATEGORY}"
def process(self, string) -> tuple:
return (string,)
class HelperNodes_MultilineStringLiteral(BaseNode):
"""
Simple String value node that allows you to specify a string to pass
into other nodes.
This node permits multiline text.
"""
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
"required": {
"string": ("STRING", {"multiline": True})
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("STRING",)
CATEGORY = f"{MODULE_CATEGORY}"
def process(self, string) -> tuple:
return (string,)