diff --git a/__init__.py b/__init__.py index 0c7fbe1..518ee89 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,12 @@ from .nodes.DOC_SaveImageAndAddToHistory import DOC_SaveImageAndAddToHistory +from .nodes.DOC_RandomPromptChoice import DOC_RandomPromptChoice # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "DOC_SaveImageAndAddToHistory": DOC_SaveImageAndAddToHistory, + "DOC_RandomPromptChoice": DOC_RandomPromptChoice, } # This magic will use a property DISPLAY_NAME on each node to get the display name of the node for the UI diff --git a/nodes/DOC_RandomPromptChoice.py b/nodes/DOC_RandomPromptChoice.py new file mode 100644 index 0000000..fbd1abb --- /dev/null +++ b/nodes/DOC_RandomPromptChoice.py @@ -0,0 +1,28 @@ +import random + +class DOC_RandomPromptChoice: + def __init__(self): + self.type = "text" + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + **{f"prompt_{i+1}": ("STRING", {"default": "", "tooltip": f"Prompt {i+1}"}) for i in range(20)} + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("selected_prompt",) + FUNCTION = "choose_random_prompt" + CATEGORY = "DOC Utils" + DISPLAY_NAME = "Random Prompt Choice" + + def choose_random_prompt(self, **kwargs): + prompts = [v for v in kwargs.values() if v.strip()] + if not prompts: + return ("",) + choice = random.choice(prompts) + idx = prompts.index(choice) + 1 + print(f"[DOC_RandomPromptChoice] Scelta #{idx}: '{choice[:20]}'") + return (choice,)