diff --git a/OneButtonPrompt-node.py b/OneButtonPrompt-node.py index 4585ba0..675415e 100644 --- a/OneButtonPrompt-node.py +++ b/OneButtonPrompt-node.py @@ -30,15 +30,14 @@ class OneButtonPrompt: return { "required": { - "prompt": ("STRING", {"input_format": {"generatedprompt": "STRING"}}) - }, - "optional": { "insanitylevel": ("INT", { "default": 5, "min": 1, #Minimum value "max": 10, #Maximum value "step": 1 #Slider's step }), + }, + "optional": { "artist": (artists, {"default": "all"}), "imagetype": (imagetypes, {"default": "all"}), "imagemodechance": ("INT", { @@ -70,19 +69,62 @@ class OneButtonPrompt: CATEGORY = "OneButtonPrompt" - def Comfy_OBP(self, prompt, insanitylevel, custom_subject,seed, artist,imagetype, subject, imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts): + def Comfy_OBP(self, insanitylevel, custom_subject,seed, artist,imagetype, subject, imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts): generatedprompt = build_dynamic_prompt(insanitylevel,subject,artist,imagetype,False,"","","",1,"",custom_subject,True,"",imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts, False) #print(generatedprompt) return (generatedprompt,) +class CreatePromptVariant: + + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "prompt_input": ("STRING", {"default": '', "multiline": True}), + }, + "optional": { + "insanitylevel": ("INT", { + "default": 5, + "min": 1, #Minimum value + "max": 10, #Maximum value + "step": 1 #Slider's step + }), + "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("prompt",) + + FUNCTION = "Comfy_OBP_PromptVariant" + + #OUTPUT_NODE = False + + CATEGORY = "OneButtonPrompt" + + def Comfy_OBP_PromptVariant(self, prompt_input, insanitylevel, seed): + generatedprompt = createpromptvariant(prompt_input, insanitylevel) + + print(generatedprompt) + + 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 + "OneButtonPrompt": OneButtonPrompt, + "CreatePromptVariant": CreatePromptVariant } # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { - "OneButtonPrompt": "One Button Prompt" + "OneButtonPrompt": "One Button Prompt", + "CreatePromptVariant": "Create Prompt Variant" } diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 0db1070..e41349f 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -2082,6 +2082,14 @@ def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender prompt = prompt.replace(",", " , ") + prompt = prompt.replace("(", " ( ") + prompt = prompt.replace(")", " ) ") + prompt = prompt.replace("[", " [ ") + prompt = prompt.replace("]", " ] ") + prompt = prompt.replace("|", " | ") + prompt = prompt.replace(":", " : ") + + prompt = " " + prompt # store the (sort of) original prompt originalprompt = prompt ### Get all combinations of 1 to 4 consecutive words @@ -2092,197 +2100,208 @@ def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender combinations_list = [] - for length in range(1, 5): # Generate combinations of length 2 and 3 + for length in range(1, 5): # Generate combinations of length 1 to 4 for start_idx in range(num_words - length + 1): end_idx = start_idx + length combination = ' '.join(words[start_idx:end_idx]) combinations_list.append(combination) + maxamountofruns = 4 + runs = 0 - while(originalprompt == prompt): - for combination in combinations_list: - lowercase_combination = combination.lower() + if(insanitylevel != 0): + print("") + print("Creating a prompt variation") + print("") + while(originalprompt == prompt and runs != maxamountofruns): + for combination in combinations_list: + lowercase_combination = combination.lower() + combination = " " + combination + " " - if lowercase_combination in [x.lower() for x in colorlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-color-") + # some rare changes if needed + if lowercase_combination in [x.lower() for x in humanlist] and chance_roll(insanitylevel, "rare"): + prompt = prompt.replace(combination," -human- ") - if lowercase_combination in [x.lower() for x in animallist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-animal-") - - if lowercase_combination in [x.lower() for x in objectlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-object-") - - if lowercase_combination in [x.lower() for x in fictionallist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-fictional-") - - - if lowercase_combination in [x.lower() for x in nonfictionallist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-nonfictional-") - - - #if lowercase_combination in [x.lower() for x in conceptsuffixlist] and chance_roll(insanitylevel, "uncommon"): - # prompt = prompt.replace(combination,"-conceptsuffix-") - - - if lowercase_combination in [x.lower() for x in buildinglist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-building-") - - - if lowercase_combination in [x.lower() for x in vehiclelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-vehicle-") - - - if lowercase_combination in [x.lower() for x in outfitlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-outfit-") - - - if lowercase_combination in [x.lower() for x in locationlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-location-") - - - if lowercase_combination in [x.lower() for x in accessorielist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-accessorie-") - - - if lowercase_combination in [x.lower() for x in artmovementlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-artmovement-") - - - if lowercase_combination in [x.lower() for x in bodytypelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-bodytype-") - - - if lowercase_combination in [x.lower() for x in cameralist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-camera-") - - - if lowercase_combination in [x.lower() for x in colorschemelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-colorscheme-") - - - #if lowercase_combination in [x.lower() for x in conceptprefixlist] and chance_roll(insanitylevel, "uncommon"): - # prompt = prompt.replace(combination,"-conceptprefix-") - - - if lowercase_combination in [x.lower() for x in culturelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-culture-") - - - if lowercase_combination in [x.lower() for x in descriptorlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-descriptor-") - - - if lowercase_combination in [x.lower() for x in directionlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-direction-") - - if lowercase_combination in [x.lower() for x in emojilist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-emoji-") + if lowercase_combination in [x.lower() for x in objecttotallist] and chance_roll(insanitylevel, "rare"): + prompt = prompt.replace(combination," -objecttotal- ") + + if lowercase_combination in [x.lower() for x in artistlist] and chance_roll(insanitylevel, "rare"): + prompt = prompt.replace(combination," -artist- ") - if lowercase_combination in [x.lower() for x in eventlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-event-") + if lowercase_combination in [x.lower() for x in colorlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -color- ") - if lowercase_combination in [x.lower() for x in focuslist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-focus-") - - - if lowercase_combination in [x.lower() for x in greatworklist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-greatwork-") - - if lowercase_combination in [x.lower() for x in haircolorlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-haircolor-") - - if lowercase_combination in [x.lower() for x in hairstylelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-hairstyle-") - - if lowercase_combination in [x.lower() for x in directionlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-direction-") - - if lowercase_combination in [x.lower() for x in humanoidlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-humanoid-") - - if lowercase_combination in [x.lower() for x in joblist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-job-") - - if lowercase_combination in [x.lower() for x in lenslist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-lens-") - if lowercase_combination in [x.lower() for x in lightinglist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-lighting-") - if lowercase_combination in [x.lower() for x in malefemalelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-malefemale-") - if lowercase_combination in [x.lower() for x in manwomanlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-manwoman-") - if lowercase_combination in [x.lower() for x in moodlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-mood-") - if lowercase_combination in [x.lower() for x in othertypelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-othertype-") - if lowercase_combination in [x.lower() for x in poselist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-pose-") - if lowercase_combination in [x.lower() for x in qualitylist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-quality-") - if lowercase_combination in [x.lower() for x in shotsizelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-shotsize-") - if lowercase_combination in [x.lower() for x in timeperiodlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-timeperiod-") - if lowercase_combination in [x.lower() for x in vomitlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-vomit-") - if lowercase_combination in [x.lower() for x in foodlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-food-") - if lowercase_combination in [x.lower() for x in genderdescriptionlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-genderdescription-") - if lowercase_combination in [x.lower() for x in minilocationlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-minilocation-") - if lowercase_combination in [x.lower() for x in minioutfitlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-minioutfit-") - if lowercase_combination in [x.lower() for x in lenslist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-lens-") - if lowercase_combination in [x.lower() for x in seasonlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-season-") - if lowercase_combination in [x.lower() for x in imagetypequalitylist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-imagetypequality-") - if lowercase_combination in [x.lower() for x in rpgclasslist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-rpgclass-") - if lowercase_combination in [x.lower() for x in brandlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-brand-") - if lowercase_combination in [x.lower() for x in spacelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-space-") - if lowercase_combination in [x.lower() for x in poemlinelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-poemline-") - if lowercase_combination in [x.lower() for x in songlinelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-songline-") - if lowercase_combination in [x.lower() for x in musicgenrelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-musicgenre-") - if lowercase_combination in [x.lower() for x in manwomanrelationlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-manwomanrelation-") - if lowercase_combination in [x.lower() for x in waterlocationlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-waterlocation-") - if lowercase_combination in [x.lower() for x in containerlist] and chance_roll(insanitylevel, "uncommon"): - print("HELLO") - prompt = prompt.replace(combination,"-container-") - if lowercase_combination in [x.lower() for x in firstnamelist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-firstname-") - if lowercase_combination in [x.lower() for x in floralist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-flora-") - - # some rare changes if needed - if lowercase_combination in [x.lower() for x in humanlist] and chance_roll(insanitylevel, "rare"): - prompt = prompt.replace(combination,"-human-") - - if lowercase_combination in [x.lower() for x in objecttotallist] and chance_roll(insanitylevel, "rare"): - prompt = prompt.replace(combination,"-objecttotal-") - - - if lowercase_combination in [x.lower() for x in fantasyartistlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-artistfantasy-") - if lowercase_combination in [x.lower() for x in popularartistlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-artistpopular-") - if lowercase_combination in [x.lower() for x in romanticismartistlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-artistromanticism-") - if lowercase_combination in [x.lower() for x in photographyartistlist] and chance_roll(insanitylevel, "uncommon"): - prompt = prompt.replace(combination,"-artistphotography-") - + if lowercase_combination in [x.lower() for x in animallist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -animal- ") + + if lowercase_combination in [x.lower() for x in objectlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -object- ") + + if lowercase_combination in [x.lower() for x in fictionallist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -fictional- ") + if lowercase_combination in [x.lower() for x in nonfictionallist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -nonfictional- ") + + + #if lowercase_combination in [x.lower() for x in conceptsuffixlist] and chance_roll(insanitylevel, "uncommon"): + # prompt = prompt.replace(combination," -conceptsuffix- ") + + + if lowercase_combination in [x.lower() for x in buildinglist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -building- ") + + + if lowercase_combination in [x.lower() for x in vehiclelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -vehicle- ") + + + if lowercase_combination in [x.lower() for x in outfitlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -outfit- ") + + + if lowercase_combination in [x.lower() for x in locationlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -location- ") + + + if lowercase_combination in [x.lower() for x in accessorielist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -accessorie- ") + + + if lowercase_combination in [x.lower() for x in artmovementlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -artmovement- ") + + + if lowercase_combination in [x.lower() for x in bodytypelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -bodytype- ") + + + if lowercase_combination in [x.lower() for x in cameralist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -camera- ") + + + if lowercase_combination in [x.lower() for x in colorschemelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -colorscheme- ") + + + #if lowercase_combination in [x.lower() for x in conceptprefixlist] and chance_roll(insanitylevel, "uncommon"): + # prompt = prompt.replace(combination," -conceptprefix- ") + + + if lowercase_combination in [x.lower() for x in culturelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -culture- ") + + + if lowercase_combination in [x.lower() for x in descriptorlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -descriptor- ") + + + if lowercase_combination in [x.lower() for x in directionlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -direction- ") + + if lowercase_combination in [x.lower() for x in emojilist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -emoji- ") + + if lowercase_combination in [x.lower() for x in eventlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -event- ") + + + if lowercase_combination in [x.lower() for x in focuslist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -focus- ") + + + if lowercase_combination in [x.lower() for x in greatworklist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -greatwork- ") + + if lowercase_combination in [x.lower() for x in haircolorlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -haircolor- ") + + if lowercase_combination in [x.lower() for x in hairstylelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -hairstyle- ") + + if lowercase_combination in [x.lower() for x in directionlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -direction- ") + + if lowercase_combination in [x.lower() for x in humanoidlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -humanoid- ") + + if lowercase_combination in [x.lower() for x in joblist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -job- ") + + if lowercase_combination in [x.lower() for x in lenslist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -lens- ") + if lowercase_combination in [x.lower() for x in lightinglist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -lighting- ") + if lowercase_combination in [x.lower() for x in malefemalelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -malefemale- ") + if lowercase_combination in [x.lower() for x in manwomanlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -manwoman- ") + if lowercase_combination in [x.lower() for x in moodlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -mood- ") + if lowercase_combination in [x.lower() for x in othertypelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -othertype- ") + if lowercase_combination in [x.lower() for x in poselist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -pose- ") + if lowercase_combination in [x.lower() for x in qualitylist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -quality- ") + if lowercase_combination in [x.lower() for x in shotsizelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -shotsize- ") + if lowercase_combination in [x.lower() for x in timeperiodlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -timeperiod- ") + if lowercase_combination in [x.lower() for x in vomitlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -vomit- ") + if lowercase_combination in [x.lower() for x in foodlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -food- ") + if lowercase_combination in [x.lower() for x in genderdescriptionlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -genderdescription- ") + if lowercase_combination in [x.lower() for x in minilocationlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -minilocation- ") + if lowercase_combination in [x.lower() for x in minioutfitlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -minioutfit- ") + if lowercase_combination in [x.lower() for x in lenslist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -lens- ") + if lowercase_combination in [x.lower() for x in seasonlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -season- ") + if lowercase_combination in [x.lower() for x in imagetypequalitylist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -imagetypequality- ") + if lowercase_combination in [x.lower() for x in rpgclasslist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -rpgclass- ") + if lowercase_combination in [x.lower() for x in brandlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -brand- ") + if lowercase_combination in [x.lower() for x in spacelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -space- ") + if lowercase_combination in [x.lower() for x in poemlinelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -poemline- ") + if lowercase_combination in [x.lower() for x in songlinelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -songline- ") + if lowercase_combination in [x.lower() for x in musicgenrelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -musicgenre- ") + if lowercase_combination in [x.lower() for x in manwomanrelationlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -manwomanrelation- ") + if lowercase_combination in [x.lower() for x in waterlocationlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -waterlocation- ") + if lowercase_combination in [x.lower() for x in containerlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -container- ") + if lowercase_combination in [x.lower() for x in firstnamelist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -firstname- ") + if lowercase_combination in [x.lower() for x in floralist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -flora- ") + + + + if lowercase_combination in [x.lower() for x in fantasyartistlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -artistfantasy- ") + if lowercase_combination in [x.lower() for x in popularartistlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -artistpopular- ") + if lowercase_combination in [x.lower() for x in romanticismartistlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -artistromanticism- ") + if lowercase_combination in [x.lower() for x in photographyartistlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -artistphotography- ") + + runs += 1 + @@ -2435,6 +2454,11 @@ def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehy return completeprompt +def replace_match(match): + # Extract the first word from the match + words = match.group(0)[1:-1].split('|') + return words[0] + def cleanup(completeprompt, advancedprompting): # first, move LoRA's to the back dynamically @@ -2450,7 +2474,12 @@ def cleanup(completeprompt, advancedprompting): if(advancedprompting==False): hybridpattern = r'\[\w+\|\w+\]' # Replace the matched pattern with the first word in the group - completeprompt = re.sub(hybridpattern, r'\1', completeprompt) + completeprompt = re.sub(hybridpattern, replace_match, completeprompt) + + # Doesnt work if there are multiple words, so then just get rid of things as is :D + completeprompt = completeprompt.replace("[", " ") + completeprompt = completeprompt.replace("]", " ") + completeprompt = completeprompt.replace("|", " ") # sometimes if there are not enough artist, we get left we things formed as (:1.2) completeprompt = re.sub('\(\:\d+\.\d+\)', '', completeprompt) diff --git a/main.py b/main.py index c02974d..04ff7c8 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ from call_extras import * from model_lists import * -def generateimages(amount = 1, size = "all",model = "currently selected model",samplingsteps = "40",cfg= "7",hiresfix = True,hiressteps ="0",denoisestrength="0.6",samplingmethod="DPM++ SDE Karras", upscaler="R-ESRGAN 4x+", hiresscale="2",apiurl="http://127.0.0.1:7860",qualitygate=False,quality="7.6",runs="5",insanitylevel="5",subject="all", artist="all", imagetype="all",silentmode=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma", img2imgbatch = "1", img2imgsamplingsteps = "20", img2imgcfg = "7", img2imgsamplingmethod = "DPM++ SDE Karras", img2imgupscaler = "R-ESRGAN 4x+", img2imgmodel = "currently selected model", img2imgactivate = False, img2imgscale = "2", img2imgpadding = "64",img2imgdenoisestrength="0.3",ultimatesdupscale=False,usdutilewidth = "512", usdutileheight = "0", usdumaskblur = "8", usduredraw ="Linear", usduSeamsfix = "None", usdusdenoise = "0.35", usduswidth = "64", usduspadding ="32", usdusmaskblur = "8",controlnetenabled=False, controlnetmodel="",img2imgdenoisestrengthmod="-0.05",enableextraupscale = False,controlnetblockymode = False,extrasupscaler1 = "all",extrasupscaler2 ="all",extrasupscaler2visiblity="0.5",extrasupscaler2gfpgan="0",extrasupscaler2codeformer="0.15",extrasupscaler2codeformerweight="0.1",extrasresize="2",onlyupscale="false",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender="all", chosensubjectsubtypeobject="all", chosensubjectsubtypehumanoid="all", chosensubjectsubtypeconcept="all", increasestability = False, qualityhiresfix = False, qualitymode = "highest", qualitykeep="keep used", basesize = "512"): +def generateimages(amount = 1, size = "all",model = "currently selected model",samplingsteps = "40",cfg= "7",hiresfix = True,hiressteps ="0",denoisestrength="0.6",samplingmethod="DPM++ SDE Karras", upscaler="R-ESRGAN 4x+", hiresscale="2",apiurl="http://127.0.0.1:7860",qualitygate=False,quality="7.6",runs="5",insanitylevel="5",subject="all", artist="all", imagetype="all",silentmode=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma", img2imgbatch = "1", img2imgsamplingsteps = "20", img2imgcfg = "7", img2imgsamplingmethod = "DPM++ SDE Karras", img2imgupscaler = "R-ESRGAN 4x+", img2imgmodel = "currently selected model", img2imgactivate = False, img2imgscale = "2", img2imgpadding = "64",img2imgdenoisestrength="0.3",ultimatesdupscale=False,usdutilewidth = "512", usdutileheight = "0", usdumaskblur = "8", usduredraw ="Linear", usduSeamsfix = "None", usdusdenoise = "0.35", usduswidth = "64", usduspadding ="32", usdusmaskblur = "8",controlnetenabled=False, controlnetmodel="",img2imgdenoisestrengthmod="-0.05",enableextraupscale = False,controlnetblockymode = False,extrasupscaler1 = "all",extrasupscaler2 ="all",extrasupscaler2visiblity="0.5",extrasupscaler2gfpgan="0",extrasupscaler2codeformer="0.15",extrasupscaler2codeformerweight="0.1",extrasresize="2",onlyupscale="false",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender="all", chosensubjectsubtypeobject="all", chosensubjectsubtypehumanoid="all", chosensubjectsubtypeconcept="all", increasestability = False, qualityhiresfix = False, qualitymode = "highest", qualitykeep="keep used", basesize = "512", promptvariantinsanitylevel = 0): loops = int(amount) # amount of images to generate steps = 0 upscalefilelist=[] @@ -122,9 +122,11 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s if(onlyupscale==False): # only do txt2img when onlyupscale is False if(silentmode==True and workprompt != ""): - randomprompt = workprompt + randomprompt = createpromptvariant(workprompt, promptvariantinsanitylevel) print("Using provided workflow prompt") - print(workprompt) + print(randomprompt) + + else: randomprompt = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, False,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept) diff --git a/prompttester.py b/prompttester.py index 40eddaa..4b7cc60 100644 --- a/prompttester.py +++ b/prompttester.py @@ -46,4 +46,4 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im print("") print("All done!") -generateprompts(100,5,"all","all","all",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","",True,"",100, "all", "all", "all", "all", False) \ No newline at end of file +generateprompts(10,5,"all","all","all",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","[hello there|cool man]",True,"",100, "all", "all", "all", "all", False) \ No newline at end of file diff --git a/promptvarianttester.py b/promptvarianttester.py index ef1726d..ac5d4b7 100644 --- a/promptvarianttester.py +++ b/promptvarianttester.py @@ -17,9 +17,10 @@ def generatepromptvariants(amount = 1,prompt="",insanitylevel="5"): insanitylevel = int(insanitylevel) while steps < loops: # build prompt - promptnew = build_dynamic_prompt(insanitylevel) + if(prompt == ""): + prompt = build_dynamic_prompt(insanitylevel) - result = createpromptvariant(promptnew, insanitylevel) + result = createpromptvariant(prompt, insanitylevel) print(result) @@ -34,4 +35,4 @@ def generatepromptvariants(amount = 1,prompt="",insanitylevel="5"): print("") print("All done!") -generatepromptvariants(1,"purple galaxy in a bottle, background is a lush jungle and a woman wearing a summer dress", 5) \ No newline at end of file +generatepromptvariants(1,"purple (galaxy) in a bottle, background is a lush jungle and a woman wearing a summer dress, -artmovement-", 0) \ No newline at end of file diff --git a/scripts/onebuttonprompt.py b/scripts/onebuttonprompt.py index 5f09eba..e579346 100644 --- a/scripts/onebuttonprompt.py +++ b/scripts/onebuttonprompt.py @@ -505,6 +505,8 @@ class Script(scripts.Script): label="Workflow mode, turns off prompt generation and uses below Workflow prompt instead.") with gr.Row(): workprompt = gr.Textbox(label="Workflow prompt") + with gr.Row(): + promptvariantinsanitylevel = gr.Slider(0, 10, value=0, step=1, label="Prompt variant. Strength of variation of workflow prompt. 0 = no variance.") with gr.Row(): gr.Markdown( """ @@ -513,6 +515,10 @@ class Script(scripts.Script): With Workflow mode, you turn off the automatic generation of new prompts on 'generate', and it will use the Workflow prompt field instead. So you can work and finetune any fun prompts without turning of the script. + You can use One Button Prompt wildcards in the workflow prompt. For example -outfit- . + + With the Prompt Variant, you can let One Button Prompt dynamically create small variance in the workflow prompt. 0 means no effect. + Below here, you can generate a set of random prompts, and send them to the Workflow prompt field. The generation of the prompt uses the settings in the Main tab. """) @@ -789,7 +795,7 @@ class Script(scripts.Script): prompt4toworkflow.click(prompttoworkflowprompt, inputs=prompt4, outputs=workprompt) prompt5toworkflow.click(prompttoworkflowprompt, inputs=prompt5, outputs=workprompt) - startmain.click(generateimages, inputs=[amountofimages,size,model,samplingsteps,cfg,hiresfix,hiressteps,denoisestrength,samplingmethod, upscaler,hiresscale, apiurl, qualitygate, quality, runs,insanitylevel,subject, artist, imagetype, silentmode, workprompt, antistring, prefixprompt, suffixprompt,negativeprompt,promptcompounderlevel, seperator, img2imgbatch, img2imgsamplingsteps, img2imgcfg, img2imgsamplingmethod, img2imgupscaler, img2imgmodel,img2imgactivate, img2imgscale, img2imgpadding,img2imgdenoisestrength,ultimatesdupscale,usdutilewidth, usdutileheight, usdumaskblur, usduredraw, usduSeamsfix, usdusdenoise, usduswidth, usduspadding, usdusmaskblur, controlnetenabled, controlnetmodel,img2imgdenoisestrengthmod,enableextraupscale,controlnetblockymode,extrasupscaler1,extrasupscaler2,extrasupscaler2visiblity,extrasupscaler2gfpgan,extrasupscaler2codeformer,extrasupscaler2codeformerweight,extrasresize,onlyupscale,givensubject,smartsubject,giventypeofimage,imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept, increasestability, qualityhiresfix, qualitymode, qualitykeep, basesize]) + startmain.click(generateimages, inputs=[amountofimages,size,model,samplingsteps,cfg,hiresfix,hiressteps,denoisestrength,samplingmethod, upscaler,hiresscale, apiurl, qualitygate, quality, runs,insanitylevel,subject, artist, imagetype, silentmode, workprompt, antistring, prefixprompt, suffixprompt,negativeprompt,promptcompounderlevel, seperator, img2imgbatch, img2imgsamplingsteps, img2imgcfg, img2imgsamplingmethod, img2imgupscaler, img2imgmodel,img2imgactivate, img2imgscale, img2imgpadding,img2imgdenoisestrength,ultimatesdupscale,usdutilewidth, usdutileheight, usdumaskblur, usduredraw, usduSeamsfix, usdusdenoise, usduswidth, usduspadding, usdusmaskblur, controlnetenabled, controlnetmodel,img2imgdenoisestrengthmod,enableextraupscale,controlnetblockymode,extrasupscaler1,extrasupscaler2,extrasupscaler2visiblity,extrasupscaler2gfpgan,extrasupscaler2codeformer,extrasupscaler2codeformerweight,extrasresize,onlyupscale,givensubject,smartsubject,giventypeofimage,imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept, increasestability, qualityhiresfix, qualitymode, qualitykeep, basesize, promptvariantinsanitylevel]) interrupt.click(tryinterrupt, inputs=[apiurl]) automatedoutputsfolderbutton.click(openfolder) @@ -952,12 +958,12 @@ class Script(scripts.Script): - return [insanitylevel,subject, artist, imagetype, prefixprompt,suffixprompt,negativeprompt, promptcompounderlevel, ANDtoggle, silentmode, workprompt, antistring, seperator, givensubject, smartsubject, giventypeofimage, imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept] + return [insanitylevel,subject, artist, imagetype, prefixprompt,suffixprompt,negativeprompt, promptcompounderlevel, ANDtoggle, silentmode, workprompt, antistring, seperator, givensubject, smartsubject, giventypeofimage, imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept, promptvariantinsanitylevel] - def run(self, p, insanitylevel, subject, artist, imagetype, prefixprompt,suffixprompt,negativeprompt, promptcompounderlevel, ANDtoggle, silentmode, workprompt, antistring,seperator, givensubject, smartsubject, giventypeofimage, imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept): + def run(self, p, insanitylevel, subject, artist, imagetype, prefixprompt,suffixprompt,negativeprompt, promptcompounderlevel, ANDtoggle, silentmode, workprompt, antistring,seperator, givensubject, smartsubject, giventypeofimage, imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept, promptvariantinsanitylevel): images = [] infotexts = [] @@ -1042,7 +1048,7 @@ class Script(scripts.Script): p.negative_prompt = negativeprompt if(silentmode == True): - p.prompt = workprompt + p.prompt = createpromptvariant(workprompt,promptvariantinsanitylevel) #for j in range(batchsize):