add boolean to indexes node

This commit is contained in:
Northumber
2025-05-04 22:55:51 +02:00
parent 78400e654a
commit 1ed8a3ccd4
3 changed files with 52 additions and 2 deletions
+4 -1
View File
@@ -9,6 +9,7 @@ from .nodes.from_dir_image_list import LoadImagesFromDirList
from .nodes.extract_metadata_by_key import ExtractMetadataByKey
from .nodes.sum_integers import SumIntegers
from .nodes.from_dir_with_index_batch import LoadImagesFromDirByIndexBatch
from .nodes.boolean_list_to_indexes import BooleanIndexesToString
NODE_CLASS_MAPPINGS = {
@@ -16,13 +17,15 @@ NODE_CLASS_MAPPINGS = {
"ExtractMetadataByKey": ExtractMetadataByKey,
"SumIntegers": SumIntegers,
"LoadImagesFromDirByIndexBatch": LoadImagesFromDirByIndexBatch,
"BooleanIndexesToString": BooleanIndexesToString,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LoadImagesFromDirList": "Load Image List from Directory",
"ExtractMetadataByKey": "Extract Metadata value by key",
"SumIntegers": "Sum Integers",
"LoadImagesFromDirByIndexBatch": "Load Image batch from Directory with indexes"
"LoadImagesFromDirByIndexBatch": "Load Image batch from Directory with indexes",
"BooleanIndexesToString": "Boolean list to index string"
}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
+46
View File
@@ -0,0 +1,46 @@
"""
This node receives a list of bools (string) and returns indexes count (formatted for the node LoadImagesFromDirByIndexBatch)
"""
class BooleanIndexesToString:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"bool_list": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("index_string",)
FUNCTION = "get_indexes"
CATEGORY = "util"
def get_indexes(self, bool_list: str):
s = bool_list.strip().replace(" ", "")
# If input contains any commas, split by commas
if "," in s:
tokens = s.split(",")
elif all(c in "01" for c in s):
tokens = list(s)
elif set(s.lower()) <= set("truefalse"):
tokens = []
i = 0
while i < len(s):
if s[i:i+4].lower() == "true":
tokens.append("true")
i += 4
elif s[i:i+5].lower() == "false":
tokens.append("false")
i += 5
else:
i += 1
else:
tokens = []
true_values = {"true", "1"}
indexes = [str(i) for i, v in enumerate(tokens) if v.lower() in true_values]
return (",".join(indexes),)
+2 -1
View File
@@ -1,2 +1,3 @@
pillow
numpy
numpy
torch