From 0b21ea010de7979d63b2e7b209ab540d6e488f18 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Sat, 3 Feb 2024 07:47:12 +0100 Subject: [PATCH] Added One Button Presets to ComfyUI --- OneButtonPromptNodes.py | 81 +++++++++++++++++++++++++++++++++++++- build_dynamic_prompt.py | 7 ++++ prompttester.py | 2 +- scripts/onebuttonprompt.py | 6 +-- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/OneButtonPromptNodes.py b/OneButtonPromptNodes.py index f8ceb31..934f78a 100644 --- a/OneButtonPromptNodes.py +++ b/OneButtonPromptNodes.py @@ -13,6 +13,10 @@ sys.path.append(onebuttonprompt_path) from build_dynamic_prompt import * from csv_reader import * +from one_button_presets import OneButtonPresets +OBPresets = OneButtonPresets() +allpresets = list(OBPresets.opb_presets.keys()) + artists = ["all", "all (wild)", "none", "popular", "greg mode", "3D", "abstract", "angular", "anime" ,"architecture", "art nouveau", "art deco", "baroque", "bauhaus", "cartoon", "character", "children's illustration", "cityscape", "cinema", "clean", "cloudscape", "collage", "colorful", "comics", "cubism", "dark", "detailed", "digital", "expressionism", "fantasy", "fashion", "fauvism", "figurativism", "gore", "graffiti", "graphic design", "high contrast", "horror", "impressionism", "installation", "landscape", "light", "line drawing", "low contrast", "luminism", "magical realism", "manga", "melanin", "messy", "monochromatic", "nature", "nudity", "photography", "pop art", "portrait", "primitivism", "psychedelic", "realism", "renaissance", "romanticism", "scene", "sci-fi", "sculpture", "seascape", "space", "stained glass", "still life", "storybook realism", "street art", "streetscape", "surrealism", "symbolism", "textile", "ukiyo-e", "vibrant", "watercolor", "whimsical"] imagetypes = ["all", "all - force multiple", "photograph", "octane render","digital art","concept art", "painting", "portrait", "anime key visual", "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode", "fixed styles mode", "the tokinator"] subjects =["all", "object", "animal", "humanoid", "landscape", "concept"] @@ -435,6 +439,78 @@ class SavePromptToFile: return ("done") +class OneButtonPreset: + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "OneButtonPreset": (allpresets, {"default": "Standard"}), + }, + "optional": { + "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), + }, + } + + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("prompt",) + + FUNCTION = "Comfy_OBP_OneButtonPreset" + + #OUTPUT_NODE = False + + CATEGORY = "OneButtonPrompt" + + def Comfy_OBP_OneButtonPreset(self, OneButtonPreset, seed): + # load the stuff + selected_opb_preset = OBPresets.get_obp_preset(OneButtonPreset) + + insanitylevel=selected_opb_preset["insanitylevel"] + subject=selected_opb_preset["subject"] + artist=selected_opb_preset["artist"] + chosensubjectsubtypeobject=selected_opb_preset["chosensubjectsubtypeobject"] + chosensubjectsubtypehumanoid=selected_opb_preset["chosensubjectsubtypehumanoid"] + chosensubjectsubtypeconcept=selected_opb_preset["chosensubjectsubtypeconcept"] + chosengender=selected_opb_preset["chosengender"] + imagetype=selected_opb_preset["imagetype"] + imagemodechance=selected_opb_preset["imagemodechance"] + givensubject=selected_opb_preset["givensubject"] + smartsubject=selected_opb_preset["smartsubject"] + givenoutfit=selected_opb_preset["givenoutfit"] + prefixprompt=selected_opb_preset["prefixprompt"] + suffixprompt=selected_opb_preset["suffixprompt"] + giventypeofimage=selected_opb_preset["giventypeofimage"] + antistring=selected_opb_preset["antistring"] + + generatedprompt = build_dynamic_prompt(insanitylevel=insanitylevel, + forcesubject=subject, + artists=artist, + subtypeobject=chosensubjectsubtypeobject, + subtypehumanoid=chosensubjectsubtypehumanoid, + subtypeconcept=chosensubjectsubtypeconcept, + gender=chosengender, + imagetype=imagetype, + imagemodechance=imagemodechance, + givensubject=givensubject, + smartsubject=smartsubject, + overrideoutfit=givenoutfit, + prefixprompt=prefixprompt, + suffixprompt=suffixprompt, + giventypeofimage=giventypeofimage, + antivalues=antistring, + advancedprompting=False, + hardturnoffemojis=True, + seed=seed + ) + + + return (generatedprompt,) + class AutoNegativePrompt: @@ -486,20 +562,21 @@ class AutoNegativePrompt: return (generatedprompt,) - - # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "OneButtonPrompt": OneButtonPrompt, + "OneButtonPreset": OneButtonPreset, "CreatePromptVariant": CreatePromptVariant, "SavePromptToFile": SavePromptToFile, "AutoNegativePrompt": AutoNegativePrompt, + } # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { "OneButtonPrompt": "One Button Prompt", + "OneButtonPreset": "One Button Preset", "CreatePromptVariant": "Create Prompt Variant", "SavePromptToFile": "Save Prompt To File", "AutoNegativePrompt": "Auto Negative Prompt", diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 4092734..f0ad1c8 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -2749,6 +2749,13 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt = completeprompt.replace("-outfit-", "-minioutfit-",1) if(rare_dist(insanitylevel)): # Use base outfit descriptor, until we are not. completeprompt = completeprompt.replace("-outfitdescriptor-", "-descriptor-") + + # if -outfit- is in the override, we want a consistent result + if("-outfit-" in overrideoutfit): + if(chance_roll(insanitylevel, "common")): + overrideoutfit = overrideoutfit.replace("-outfit-", random.choice(outfitlist)) + else: + overrideoutfit = overrideoutfit.replace("-outfit-", random.choice(minioutfitlist)) if(overrideoutfit != ""): completeprompt = completeprompt.replace("-sameoutfit-", overrideoutfit) diff --git a/prompttester.py b/prompttester.py index d91d03d..2b75d73 100644 --- a/prompttester.py +++ b/prompttester.py @@ -46,7 +46,7 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im print(result) break - if(overrideoutfit != "" and overrideoutfit not in result and onlyartists == False): + if(overrideoutfit != "" and overrideoutfit not in result and onlyartists == False and "-outfit-" not in overrideoutfit): print("The outfit override is not showing up!") print("") print(result) diff --git a/scripts/onebuttonprompt.py b/scripts/onebuttonprompt.py index 3e1f812..04492b0 100644 --- a/scripts/onebuttonprompt.py +++ b/scripts/onebuttonprompt.py @@ -268,9 +268,9 @@ class Script(scripts.Script): One Button Prompt is now active. Just press the normal Generate button to start generating images. - The settings below give you more control over what you wish to generate. + Presets can be used to store and load settings. - Presets can be used to store and load settings. + Set the One Button Preset to "Custom..." to show all settings. The settings below give you more control over what you wish to generate. """) # Part of presets @@ -278,7 +278,7 @@ class Script(scripts.Script): OBP_preset = gr.Dropdown( label="One Button Preset", choices=[OBPresets.CUSTOM_OBP] + list(OBPresets.opb_presets.keys()), - value="Custom...", + value="Standard", )