diff --git a/__init__.py b/__init__.py index 6a1fd0c..e531354 100644 --- a/__init__.py +++ b/__init__.py @@ -5,7 +5,7 @@ @description: A custom node that pauses the flow while you choose which image or images to pass on to the rest of the workflow. Simplified and improved version of cg-image-picker. """ -VERSION = "1.9.1" +VERSION = "1.9.2" WEB_DIRECTORY = "./js" __all__ = ["WEB_DIRECTORY"] diff --git a/js/image_filter.js b/js/image_filter.js index c826cc4..c9b731e 100644 --- a/js/image_filter.js +++ b/js/image_filter.js @@ -8,7 +8,7 @@ import { Log } from "./log.js"; const FILTER_TYPES = ["Image Filter","Text Image Filter","Text Image Filter with Extras","Mask Image Filter", "Image Filter for List"] -const VERSION = "1.9.1" +const VERSION = "1.9.2" app.registerExtension({ name: "cg.image_filter", diff --git a/pyproject.toml b/pyproject.toml index 364a990..8c04c31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "cg-image-filter" description = "A set of custom nodes that pause a workflow while you select images, add masks, or edit text." -version = "1.9.1" +version = "1.9.2" license = { file = "LICENSE" } [project.urls] diff --git a/utility_nodes/list_utility_nodes.py b/utility_nodes/list_utility_nodes.py index d9c8252..fcfda3b 100644 --- a/utility_nodes/list_utility_nodes.py +++ b/utility_nodes/list_utility_nodes.py @@ -1,5 +1,6 @@ import torch from comfy_api.latest import io +from typing import Iterable class BatchFromImageList(io.ComfyNode): @classmethod @@ -43,19 +44,23 @@ class ImageListFromBatch(io.ComfyNode): def execute(cls, images): # type: ignore image_list = list( i.unsqueeze(0) for i in images ) return io.NodeOutput(image_list,) - + +template = io.MatchType.Template("pick_from_list") + class PickFromList(io.ComfyNode): @classmethod def define_schema(cls): return io.Schema( node_id = "Pick from List", display_name = "Pick from List", + description = "Given a comma separated list of indexes, return only those entries from the input list.", inputs = [ - io.AnyType.Input("anything"), - io.String.Input("indexes", display_name="indexes", tooltip="comma separated list of indexes. Whitespace stripped. Only these entries will be included. Zero indexed.") + io.MatchType.Input("anything", template=template, tooltip="note that a list is expected (or an image batch)"), + io.String.Input("indexes", display_name="indexes", tooltip="comma separated list of indexes. Whitespace stripped. Only these entries will be included."), + io.Combo.Input("indexing", options=['0','1'], default='0', tooltip="is the first item number 0 or number 1?") ], outputs = [ - io.String.Output("picks", display_name="picks", is_output_list=True) + io.MatchType.Output(template=template, display_name="picks", is_output_list=True) ], category = "image_filter/helpers", is_input_list=True @@ -63,19 +68,25 @@ class PickFromList(io.ComfyNode): @classmethod - def execute(cls, anything:list, indexes:list[str]): # type: ignore + def execute(cls, anything:list, indexes:list[str], indexing:list[str|int]=[0,]): # type: ignore - if len(anything)==1 and isinstance(anything[0],list): - print("Warning: received list of lists. Processing just anything[0]") - anything = anything[0] + is_image_batch = False + if len(anything)==1: + if isinstance(anything[0],list): + print("Warning: PickFromList received length 1 list of lists. Processing anything[0]") + anything = anything[0] + elif isinstance(anything[0], torch.Tensor) and len(anything[0].shape) == 4: + anything = anything[0] # type: ignore + is_image_batch = True index_str:str = indexes[0] + offset:int = int(indexing[0]) - result = [] - for x in [x.strip() for x in index_str.split(',')]: - try: - result.append(anything[int(x)]) - except Exception as e: - print(f"{e} when processing {x} from {index_str}") - - return io.NodeOutput(result, ) \ No newline at end of file + try: + index_ns = [int(x.strip())-offset for x in index_str.split(',') if x.strip()] + result = [anything[x] for x in index_ns] + if is_image_batch: result = [torch.stack(result),] + return io.NodeOutput(result, ) + except Exception as e: + print(f"{e} when processing {index_str}") + raise