Add Random Prompt Choice
This commit is contained in:
parent
241aeb7c69
commit
89197dce65
@ -1,10 +1,12 @@
|
|||||||
from .nodes.DOC_SaveImageAndAddToHistory import DOC_SaveImageAndAddToHistory
|
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
|
# A dictionary that contains all nodes you want to export with their names
|
||||||
# NOTE: names should be globally unique
|
# NOTE: names should be globally unique
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"DOC_SaveImageAndAddToHistory": DOC_SaveImageAndAddToHistory,
|
"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
|
# This magic will use a property DISPLAY_NAME on each node to get the display name of the node for the UI
|
||||||
|
28
nodes/DOC_RandomPromptChoice.py
Normal file
28
nodes/DOC_RandomPromptChoice.py
Normal file
@ -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,)
|
Loading…
x
Reference in New Issue
Block a user