Skip to content

Commit 391792c

Browse files
committed
BatchCreativeInterpolationNodeDynamicSettings added
1 parent a819e6d commit 391792c

File tree

5 files changed

+112
-6
lines changed

5 files changed

+112
-6
lines changed

__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"ImageCropByRatio": ImageCropByRatio,
3131
"ImageCropByRatioAndResize": ImageCropByRatioAndResize,
3232
"ImagesCropByRatioAndResizeBatch": ImagesCropByRatioAndResizeBatch,
33+
"BatchCreativeInterpolationNodeDynamicSettings": BatchCreativeInterpolationNodeDynamicSettings,
3334
}
3435

3536
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -55,6 +56,7 @@
5556
"ImageCropByRatio": "ImageCropByRatio",
5657
"ImageCropByRatioAndResize": "ImageCropByRatioAndResize",
5758
"ImagesCropByRatioAndResizeBatch": "ImagesCropByRatioAndResizeBatch",
59+
"BatchCreativeInterpolationNodeDynamicSettings": "BatchCreativeInterpolationNodeDynamicSettings",
5860
}
5961

6062

js/widgethider.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ const nodeWidgetHandlers = {
109109
"UltimateVideoLoader (simple)": {
110110
"source": handleUltimateVideoLoaderSource,
111111
},
112+
"BatchCreativeInterpolationNodeDynamicSettings": {
113+
"image_count": handleBatchCreativeInterpolationNodeDynamicSettingsVisibility,
114+
}
112115
};
113116

114117
// In the main function where widgetLogic is called
@@ -145,13 +148,42 @@ function handleUltimateVideoLoaderVisibility(node, source) {
145148
}
146149
}
147150

151+
function handleBatchCreativeInterpolationNodeDynamicSettingsVisibility(node, widget) {
152+
handleVisibility(node, widget.value, "BatchCreativeInterpolationNodeDynamicSettings")
153+
}
154+
155+
const MAX_COUNT_VALUE = 50
148156

149157
function handleUltimateVideoLoaderSource(node, widget) {
150158
handleInputModeWidgetsVisibility(node, widget.value);
151159
handleUltimateVideoLoaderVisibility(node, widget.value);
152160
}
153161

162+
function handleVisibility(node, countValue, nodeType) {
163+
const baseNamesMap = {
164+
"BatchCreativeInterpolationNodeDynamicSettings": [
165+
"frame_distribution",
166+
"key_frame_influence",
167+
"min_strength_value",
168+
"max_strength_value",
169+
],
170+
}
171+
const baseNames = baseNamesMap[nodeType]
154172

173+
174+
for (let i=1; i <= MAX_COUNT_VALUE; i++) {
175+
const widgets = baseNames.map((n) => findWidgetByName(node, `${n}_${i}`))
176+
177+
if (i <= countValue) {
178+
widgets?.forEach((w) => {
179+
180+
toggleWidget(node, w, true)}
181+
)
182+
} else {
183+
widgets?.forEach((w) => toggleWidget(node, w, false))
184+
}
185+
}
186+
}
155187

156188
app.registerExtension({
157189
name: "komojini.widgethider",

komojini_server.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ async def get_path(request):
214214
def is_prompt_node_type_of(node_value, node_type: str) -> bool:
215215
return node_type in node_value.get("class_type", "") or node_type in node_value.get("_meta", {}).get("tile", "")
216216

217+
217218
def is_workflow_node_type_of(node_value, node_type: str) -> bool:
218219
return node_type in node_value.get("type", "")
219220

@@ -247,22 +248,27 @@ def search_setter_getter_connected_nodes(json_data):
247248
inputs = v["inputs"]
248249

249250
if is_prompt_node_type_of(v, "Get"):
250-
key = inputs["key"]
251+
key = inputs.get("key")
252+
if not key:
253+
continue
251254

252-
if key and class_type.endswith("CachedGetter") and CACHED_MAP.get(key, None) is not None:
255+
if class_type.endswith("CachedGetter") and CACHED_MAP.get(key, None) is not None:
253256
continue
254257

255258
if key in key_to_getter_node_ids:
256259
key_to_getter_node_ids[key].append(node_id)
257260
else:
258261
key_to_getter_node_ids[key] = [node_id]
259262
elif is_prompt_node_type_of(v, "Set"):
260-
key = inputs["key"]
263+
key = inputs.get("key")
264+
if not key:
265+
continue
261266
key_to_setter_node_id[key] = node_id
267+
262268
return key_to_getter_node_ids, key_to_setter_node_id
263269

264270

265-
def search_setter_getter_from_workflow(json_data):
271+
def search_setter_getter_from_workflow_test(json_data):
266272
key_to_getter_node_ids = {}
267273
key_to_setter_node_id = {}
268274

@@ -345,6 +351,22 @@ def search_setter_getter_from_workflow(json_data):
345351
print_info(f"{not_included_nodes_count} Nodes not included in prompt but is activated")
346352
return key_to_getter_node_ids, key_to_setter_node_id
347353

354+
def search_setter_getter_from_workflow(json_data):
355+
key_to_getter_node_ids = {}
356+
key_to_setter_node_id = {}
357+
358+
workflow = json_data["extra_data"]["extra_pnginfo"]["workflow"]
359+
nodes = workflow["nodes"]
360+
prompt = json_data["prompt"]
361+
362+
not_included_nodes_count = 0
363+
for node in nodes:
364+
if node["mode"] == 0 and node["id"] not in prompt:
365+
not_included_nodes_count += 1
366+
367+
print_info(f"{not_included_nodes_count} Nodes not included in prompt but is activated")
368+
return key_to_getter_node_ids, key_to_setter_node_id
369+
348370

349371
def connect_to_from_nodes(json_data):
350372
prompt = json_data["prompt"]
@@ -384,7 +406,7 @@ def workflow_update(json_data):
384406

385407
def on_prompt_handler(json_data):
386408
try:
387-
test_prompt(json_data)
409+
# test_prompt(json_data)
388410
search_setter_getter_from_workflow(json_data)
389411
connect_to_from_nodes(json_data)
390412

nodes/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"DragNUWAImageCanvas",
2323
"ImageCropByRatio",
2424
"ImageCropByRatioAndResize",
25-
"ImagesCropByRatioAndResizeBatch"
25+
"ImagesCropByRatioAndResizeBatch",
26+
"BatchCreativeInterpolationNodeDynamicSettings",
2627
]

nodes/komojini_nodes.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,54 @@ def run(self, image, tracking_points, **kwargs):
263263
return (image, tracking_points, )
264264

265265

266+
MAX_IMAGE_COUNT = 50
267+
268+
class BatchCreativeInterpolationNodeDynamicSettings:
269+
@classmethod
270+
def INPUT_TYPES(s):
271+
inputs = {
272+
"required": {
273+
"image_count": ("INT", {"default": 1, "min": 1, "max": MAX_IMAGE_COUNT, "step": 1}),
274+
},
275+
}
276+
277+
for i in range(1, MAX_IMAGE_COUNT):
278+
if i == 1:
279+
inputs["required"][f"frame_distribution_{i}"] = ("INT", {"default": 4, "min": 4, "max": 64, "step": 1})
280+
else:
281+
inputs["required"][f"frame_distribution_{i}"] = ("INT", {"default": 16, "min": 4, "max": 64, "step": 1})
282+
283+
inputs["required"][f"key_frame_influence_{i}"] = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.1})
284+
inputs["required"][f"min_strength_value_{i}"] = ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.1})
285+
inputs["required"][f"max_strength_value_{i}"] = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.1})
286+
287+
return inputs
288+
289+
RETURN_TYPES = ("STRING", "STRING", "STRING",)
290+
RETURN_NAMES = ("dynamic_frame_distribution_values", "dynamic_key_frame_influence_values", "dynamic_strength_values",)
291+
292+
FUNCTION = "run"
293+
294+
def run(self, image_count, **kwargs):
295+
dynamic_frame_distribution_values = ""
296+
dynamic_key_frame_influence_values = ""
297+
dynamic_strength_values = ""
298+
299+
previous_frame_distribution = 0
300+
301+
for i in range(1, image_count+1):
302+
previous_frame_distribution += kwargs.get(f"frame_distribution_{i}", 0)
303+
304+
distribution_value = str(previous_frame_distribution) + ","
305+
influence_value = str(kwargs.get(f"key_frame_influence_{i}")) + ","
306+
strength_value = "({min},{max}),".format(min=kwargs.get(f"min_strength_value_{i}"), max=kwargs.get(f"max_strength_value_{i}"))
307+
308+
dynamic_frame_distribution_values += distribution_value
309+
dynamic_key_frame_influence_values += influence_value
310+
dynamic_strength_values += strength_value
311+
312+
return (dynamic_frame_distribution_values[:-1], dynamic_key_frame_influence_values[:-1], dynamic_strength_values[:-1],)
313+
266314
__all__ = [
267315
"To",
268316
"From",
@@ -271,4 +319,5 @@ def run(self, image, tracking_points, **kwargs):
271319
"FlowBuilder",
272320
"FlowBuilderSetter",
273321
"DragNUWAImageCanvas",
322+
"BatchCreativeInterpolationNodeDynamicSettings",
274323
]

0 commit comments

Comments
 (0)