Skip to content

Commit

Permalink
Merge pull request #48 from sipherxyz/add_textrandom_node
Browse files Browse the repository at this point in the history
Add TextRandomMultiline node
  • Loading branch information
tungnguyensipher authored Oct 21, 2024
2 parents 6bf9ad1 + 4820b0d commit af63018
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions modules/utility_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,32 @@ def merge_models(self, model1, model2, ratio=1.0):
return (m,)


class UtilTextRandomMultiline:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"amount": ("INT", {"default": 1, "min": 1, "max": 1024}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}),
},
}

RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("lines",)
OUTPUT_IS_LIST = (True,)
CATEGORY = "Art Venture/Utils"
FUNCTION = "random_multiline"

def random_multiline(self, text: str, amount=1, seed=0):
lines = text.strip().split("\n")
lines = [line.strip() for line in lines if line.strip()]

custom_random = random.Random(seed)
custom_random.shuffle(lines)
return (lines[:amount],)


NODE_CLASS_MAPPINGS = {
"LoadImageFromUrl": UtilLoadImageFromUrl,
"LoadImageAsMaskFromUrl": UtilLoadImageAsMaskFromUrl,
Expand Down Expand Up @@ -1163,6 +1189,7 @@ def merge_models(self, model1, model2, ratio=1.0):
"RandomFloat": UtilRandomFloat,
"NumberScaler": UtilNumberScaler,
"MergeModels": UtilModelMerge,
"TextRandomMultiline": UtilTextRandomMultiline,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LoadImageFromUrl": "Load Image From URL",
Expand Down Expand Up @@ -1197,4 +1224,5 @@ def merge_models(self, model1, model2, ratio=1.0):
"RandomFloat": "Random Float",
"NumberScaler": "Number Scaler",
"MergeModels": "Merge Models",
"TextRandomMultiline": "Text Random Multiline",
}

0 comments on commit af63018

Please sign in to comment.