3 Commits
2 changed files with 16 additions and 11 deletions
+15 -10
View File
@@ -4,6 +4,7 @@ from PIL import Image
import numpy as np
from comfy_execution.graph_utils import GraphBuilder, is_link
import folder_paths
from ..tools.tools import VariantSupport
import torch.nn.functional as F
@@ -63,8 +64,13 @@ class BatchImageLoopOpenSun:
if batch_id is None:
batch_id = uuid.uuid4().hex[:8]
batch_path = os.path.join(output_dir, batch_id) if output_dir else ""
if batch_path and iteration_count == 0:
base_output = folder_paths.get_output_directory()
if output_dir:
batch_path = os.path.join(base_output, output_dir, batch_id)
else:
batch_path = os.path.join(base_output, "loop_batch", batch_id)
if iteration_count == 0:
os.makedirs(batch_path, exist_ok=True)
print(f"[chen] Created batch directory: {batch_path}")
@@ -93,6 +99,7 @@ class BatchImageLoopCloseSun:
"current_image": ("IMAGE",),
"max_iterations": ("INT", {"forceInput": True}),
"batch_path": ("STRING", {"forceInput": True}),
"iteration_count": ("INT", {"forceInput": True}),
},
"optional": {
"pass_back": ("BOOLEAN", {"default": False}),
@@ -100,7 +107,6 @@ class BatchImageLoopCloseSun:
"hidden": {
"dynprompt": "DYNPROMPT",
"unique_id": "UNIQUE_ID",
"iteration_count": ("INT", {"default": 0}),
}
}
@@ -116,11 +122,12 @@ class BatchImageLoopCloseSun:
return image
def save_image(self, image, batch_path, index):
if not batch_path:
filepath = os.path.join(batch_path, f"{index:05d}.png")
if os.path.exists(filepath):
print(f"[chen] Skip (exists): {filepath}")
return
img_np = (image.squeeze(0).cpu().numpy() * 255).clip(0, 255).astype(np.uint8)
img_pil = Image.fromarray(img_np)
filepath = os.path.join(batch_path, f"{index:05d}.png")
img_pil.save(filepath)
print(f"[chen] Saved: {filepath}")
@@ -135,7 +142,7 @@ class BatchImageLoopCloseSun:
return torch.cat(results, dim=0).to(device)
def while_loop_close(self, flow_control, current_image, max_iterations, batch_path,
pass_back=False, iteration_count=0,
iteration_count, pass_back=False,
dynprompt=None, unique_id=None):
print(f"[chen] Iteration {iteration_count} / {max_iterations}")
@@ -149,10 +156,7 @@ class BatchImageLoopCloseSun:
if iteration_count == max_iterations - 1:
print(f"[chen] Loop finished, loading results from {batch_path}")
if batch_path:
result_images = self.load_all_images(batch_path, max_iterations, device)
else:
result_images = current_image
result_images = self.load_all_images(batch_path, max_iterations, device)
return (result_images, batch_path)
open_node = flow_control[0]
@@ -202,6 +206,7 @@ class BatchImageLoopCloseSun:
new_open = graph.lookup_node(open_node)
new_open.set_input("iteration_count", iteration_count + 1)
new_open.set_input("batch_id", os.path.basename(batch_path))
if pass_back:
new_open.set_input("previous_image", current_image)
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "comfyui_sun_nodes"
version = "0.1.2"
version = "0.1.5"
description = "Custom ComfyUI nodes by SunX.AI"
authors = [
{name = "SunX AI", email = "sunx.ai@hotmail.com"}