From 2fe8b30e96052d4da6701d8ac1713049c9fa5ce5 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Tue, 1 Aug 2023 20:33:10 +0200 Subject: [PATCH 1/8] Update build_dynamic_prompt.py --- build_dynamic_prompt.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index ae2bdf8..baeb067 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -10,7 +10,7 @@ from random_functions import * # insanity level controls randomness of propmt 0-10 # forcesubject van be used to force a certain type of subject # Set artistmode to none, to exclude artists -def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all", imagetype = "all", onlyartists = False, antivalues = "", prefixprompt = "", suffixprompt ="",promptcompounderlevel ="1", seperator = "comma", givensubject="",smartsubject = True,giventypeofimage="", imagemodechance = 20, gender = "all", subtypeobject="all", subtypehumanoid="all", subtypeconcept="all"): +def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all", imagetype = "all", onlyartists = False, antivalues = "", prefixprompt = "", suffixprompt ="",promptcompounderlevel ="1", seperator = "comma", givensubject="",smartsubject = True,giventypeofimage="", imagemodechance = 20, gender = "all", subtypeobject="all", subtypehumanoid="all", subtypeconcept="all", advancedprompting=True): # load the config file @@ -1085,6 +1085,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if modeselector < 5 and end - step >= 2: artistmodeslist = ["hybrid", "stopping", "adding", "switching", "enhancing"] artistmode = artistmodeslist[modeselector] + if(advancedprompting == False): + artistmode = "normal" if (artistmode in ["hybrid","switching"] and end - step == 1): artistmode = "normal" @@ -1137,7 +1139,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if(onlyartists == True): # replace artist wildcards - completeprompt = replacewildcard(completeprompt, insanitylevel, "-artist-", artistlist, False) + completeprompt = replacewildcard(completeprompt, insanitylevel, "-artist-", artistlist, False, False) # clean it up completeprompt = cleanup(completeprompt) @@ -1252,7 +1254,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # if we have a given subject, we should skip making an actual subject if(givensubject == ""): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1285,7 +1287,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # if we have a given subject, we should skip making an actual subject if(givensubject == ""): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1326,7 +1328,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += "-job- " if(subjectchooser == "fictional"): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1340,7 +1342,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all hybridorswap = "" if(subjectchooser == "non fictional"): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1356,7 +1358,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if(subjectchooser == "humanoid"): if(gender != "all"): completeprompt += "-malefemale- " - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1370,7 +1372,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all hybridorswap = "" if(subjectchooser == "firstname"): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1395,7 +1397,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # if we have a given subject, we should skip making an actual subject if(givensubject == ""): - if rare_dist(insanitylevel): + if(rare_dist(insanitylevel) and advancedprompting == True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" @@ -1764,6 +1766,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if modeselector < 4 and end - step >= 2: artistmodeslist = ["hybrid", "stopping", "adding", "switching"] artistmode = artistmodeslist[modeselector] + if(advancedprompting == False): + artistmode = "normal" if artistmode in ["hybrid","switching"] and end - step == 1: artistmode = "normal" # if there are not enough artists in the list, then just go normal @@ -1924,13 +1928,13 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # keywordsinstring = any(word.lower() in givensubject.lower() for word in keywordslist) for wildcard in allwildcardslistnohybrid: attachedlist = allwildcardslistnohybridlists[allwildcardslistnohybrid.index(wildcard)] - completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,False) + completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,False, advancedprompting) for wildcard in allwildcardslistwithhybrid: attachedlist = allwildcardslistwithhybridlists[allwildcardslistwithhybrid.index(wildcard)] - completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,True) + completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,True, advancedprompting) @@ -1949,7 +1953,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # function -def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehybridorswap): +def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehybridorswap, advancedprompting): if(len(listname) == 0): # handling empty lists @@ -1957,7 +1961,7 @@ def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehy else: while wildcard in completeprompt: - if(unique_dist(insanitylevel) and activatehybridorswap == True and len(listname)>2): + if(unique_dist(insanitylevel) and activatehybridorswap == True and len(listname)>2 and advancedprompting==True): hybridorswaplist = ["hybrid", "swap"] hybridorswap = random.choice(hybridorswaplist) replacementvalue = random.choice(listname) From b9bf99c3c3ef3990c893698e4d4bf4d53615bf64 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Wed, 2 Aug 2023 21:48:44 +0200 Subject: [PATCH 2/8] Working on prompt variant mode --- OneButtonPrompt-node.py | 2 +- build_dynamic_prompt.py | 452 +++++++++++++++++++++++++++++++++++++++- csvfiles/hairstyles.csv | 2 +- csvfiles/outfits.csv | 1 + prompttester.py | 6 +- promptvarianttester.py | 37 ++++ 6 files changed, 492 insertions(+), 8 deletions(-) create mode 100644 promptvarianttester.py diff --git a/OneButtonPrompt-node.py b/OneButtonPrompt-node.py index a0e1708..4585ba0 100644 --- a/OneButtonPrompt-node.py +++ b/OneButtonPrompt-node.py @@ -71,7 +71,7 @@ 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): - 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) + 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,) diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index baeb067..0db1070 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -1142,7 +1142,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt = replacewildcard(completeprompt, insanitylevel, "-artist-", artistlist, False, False) # clean it up - completeprompt = cleanup(completeprompt) + completeprompt = cleanup(completeprompt, advancedprompting) print("only generated these artists:" + completeprompt) return completeprompt @@ -1940,7 +1940,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # clean it up - completeprompt = cleanup(completeprompt) + completeprompt = cleanup(completeprompt, advancedprompting) #just for me, some fun with posting fake dev messages (ala old sim games) if(random.randint(1, 50)==1): @@ -1952,6 +1952,447 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all return completeprompt +# function that takes an existing prompt and tries to create a variant out of it +def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender = "all", artists = "all", advancedprompting = True): + # first load the lists, all copied from above (can that be done better?) + # do we want to use the same settings or keep it open?? + + # first build up a complete anti list. Those values are removing during list building + # this uses the antivalues string AND the antilist.csv + emptylist = [] + antilist = csv_to_list("antilist",emptylist , "./userfiles/",1) + antivaluelist = antivalues.split(",") + + antilist += antivaluelist + + # build all lists here + + colorlist = csv_to_list("colors",antilist) + animallist = csv_to_list("animals",antilist) + materiallist = csv_to_list("materials",antilist) + objectlist = csv_to_list("objects",antilist) + fictionallist = csv_to_list(csvfilename="fictional characters",antilist=antilist,skipheader=True,gender=gender) + nonfictionallist = csv_to_list(csvfilename="nonfictional characters",antilist=antilist,skipheader=True,gender=gender) + conceptsuffixlist = csv_to_list("concept_suffix",antilist) + buildinglist = csv_to_list("buildings",antilist) + vehiclelist = csv_to_list("vehicles",antilist) + outfitlist = csv_to_list("outfits",antilist) + locationlist = csv_to_list("locations",antilist) + + accessorielist = csv_to_list("accessories",antilist) + artmovementlist = csv_to_list("artmovements",antilist) + bodytypelist = csv_to_list("body_types",antilist) + cameralist = csv_to_list("cameras",antilist) + colorschemelist = csv_to_list("colorscheme",antilist) + conceptprefixlist = csv_to_list("concept_prefix",antilist) + culturelist = csv_to_list("cultures",antilist) + descriptorlist = csv_to_list("descriptors",antilist) + devmessagelist = csv_to_list("devmessages",antilist) + directionlist = csv_to_list("directions",antilist) + emojilist = csv_to_list("emojis",antilist) + eventlist = csv_to_list("events",antilist) + focuslist = csv_to_list("focus",antilist) + greatworklist = csv_to_list("greatworks",antilist) + haircolorlist = csv_to_list("haircolors",antilist) + hairstylelist = csv_to_list("hairstyles",antilist) + humanactivitylist = csv_to_list("human_activities",antilist) + humanoidlist = csv_to_list("humanoids",antilist) + imagetypelist = csv_to_list("imagetypes",antilist) + joblist = csv_to_list("jobs",antilist) + lenslist = csv_to_list("lenses",antilist) + lightinglist = csv_to_list("lighting",antilist) + malefemalelist = csv_to_list(csvfilename="malefemale",antilist=antilist,skipheader=True,gender=gender) + manwomanlist = csv_to_list(csvfilename="manwoman",antilist=antilist,skipheader=True,gender=gender) + moodlist = csv_to_list("moods",antilist) + othertypelist = csv_to_list("othertypes",antilist) + poselist = csv_to_list("poses",antilist) + qualitylist = csv_to_list("quality",antilist) + shotsizelist = csv_to_list("shotsizes",antilist) + timeperiodlist = csv_to_list("timeperiods",antilist) + vomitlist = csv_to_list("vomit",antilist) + foodlist = csv_to_list("foods", antilist) + genderdescriptionlist = csv_to_list(csvfilename="genderdescription",antilist=antilist,skipheader=True,gender=gender) + minilocationlist = csv_to_list("minilocations", antilist) + minioutfitlist = csv_to_list("minioutfits", antilist) + seasonlist = csv_to_list("seasons", antilist) + elaborateoutfitlist = csv_to_list("elaborateoutfits", antilist) + minivomitlist = csv_to_list("minivomit", antilist) + imagetypequalitylist = csv_to_list("imagetypequality", antilist) + rpgclasslist = csv_to_list("rpgclasses", antilist) + brandlist = csv_to_list("brands", antilist) + spacelist = csv_to_list("space", antilist) + poemlinelist = csv_to_list("poemlines", antilist) + songlinelist = csv_to_list("songlines", antilist) + musicgenrelist = csv_to_list("musicgenres", antilist) + manwomanrelationlist = csv_to_list(csvfilename="manwomanrelations",antilist=antilist,skipheader=True,gender=gender) + waterlocationlist = csv_to_list("waterlocations", antilist) + containerlist = csv_to_list("containers", antilist) + firstnamelist = csv_to_list(csvfilename="firstnames",antilist=antilist,skipheader=True,gender=gender) + floralist = csv_to_list("flora", antilist) + + humanlist = fictionallist + nonfictionallist + humanoidlist + malefemalelist + manwomanlist + manwomanrelationlist + objecttotallist = objectlist + buildinglist + vehiclelist + foodlist + spacelist + floralist + + # build artists list + artistlist = [] + # create artist list to use in the code, maybe based on category or personal lists + if(artists != "all" and artists != "none" and artists.startswith("personal_artists") == False and artists.startswith("personal artists") == False): + artistlist = artist_category_csv_to_list("artists_and_category",artists) + elif(artists.startswith("personal_artists") == True or artists.startswith("personal artists") == True): + artists = artists.replace(" ","_",-1) # add underscores back in + artistlist = csv_to_list(artists,antilist,"./userfiles/") + elif(artists != "none"): + artistlist = csv_to_list("artists",antilist) + + # create special artists lists, used in templates + fantasyartistlist = artist_category_csv_to_list("artists_and_category","fantasy") + popularartistlist = artist_category_csv_to_list("artists_and_category","popular") + romanticismartistlist = artist_category_csv_to_list("artists_and_category","romanticism") + photographyartistlist = artist_category_csv_to_list("artists_and_category","photography") + + + # add any other custom lists + stylestiloralist = csv_to_list("styles_ti_lora",antilist,"./userfiles/") + generatestyle = bool(stylestiloralist) # True of not empty + + custominputprefixlist = csv_to_list("custom_input_prefix",antilist,"./userfiles/") + generatecustominputprefix = bool(custominputprefixlist) # True of not empty + + custominputmidlist = csv_to_list("custom_input_mid",antilist,"./userfiles/") + generatecustominputmid = bool(custominputmidlist) # True of not empty + + custominputsuffixlist = csv_to_list("custom_input_suffix",antilist,"./userfiles/") + generatecustominputsuffix = bool(custominputsuffixlist) # True of not empty + + customsubjectslist = csv_to_list("custom_subjects",antilist,"./userfiles/") + + # special lists + backgroundtypelist = csv_to_list("backgroundtypes", antilist,"./csvfiles/special_lists/") + insideshotlist = csv_to_list("insideshots", antilist,"./csvfiles/special_lists/") + photoadditionlist = csv_to_list("photoadditions", antilist,"./csvfiles/special_lists/") + buildhairlist = csv_to_list("buildhair", antilist,"./csvfiles/special_lists/") + buildoutfitlist = csv_to_list("buildoutfit", antilist,"./csvfiles/special_lists/") + objectadditionslist = csv_to_list("objectadditions", antilist,"./csvfiles/special_lists/") + humanadditionlist = csv_to_list("humanadditions", antilist,"./csvfiles/special_lists/") + animaladditionlist = csv_to_list("animaladditions", antilist,"./csvfiles/special_lists/") + buildaccessorielist = csv_to_list("buildaccessorie", antilist,"./csvfiles/special_lists/") + minilocationadditionslist = csv_to_list("minilocationadditions", antilist,"./csvfiles/special_lists/") + overalladditionlist = csv_to_list("overalladditions", antilist,"./csvfiles/special_lists/") + imagetypemodelist = csv_to_list("imagetypemodes", antilist,"./csvfiles/special_lists/") + + + prompt = prompt.replace(",", " , ") + # store the (sort of) original prompt + originalprompt = prompt + ### Get all combinations of 1 to 4 consecutive words + + + words = prompt.split() + num_words = len(words) + + combinations_list = [] + + for length in range(1, 5): # Generate combinations of length 2 and 3 + 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) + + + while(originalprompt == prompt): + for combination in combinations_list: + lowercase_combination = combination.lower() + + 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 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"): + 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-") + + + + + + + + completeprompt = prompt + + + while ( + "-color-" in completeprompt or + "-material-" in completeprompt or + "-animal-" in completeprompt or + "-object-" in completeprompt or + "-fictional-" in completeprompt or + "-nonfictional-" in completeprompt or + "-conceptsuffix-" in completeprompt or + "-building-" in completeprompt or + "-vehicle-" in completeprompt or + "-outfit-" in completeprompt or + "-location-" in completeprompt or + "-conceptprefix-" in completeprompt or + "-descriptor-" in completeprompt or + "-food-" in completeprompt or + "-haircolor-" in completeprompt or + "-hairstyle-" in completeprompt or + "-job-" in completeprompt or + "-culture-" in completeprompt or + "-accessory-" in completeprompt or + "-humanoid-" in completeprompt or + "-manwoman-" in completeprompt or + "-human-" in completeprompt or + "-colorscheme-" in completeprompt or + "-mood-" in completeprompt or + "-genderdescription-" in completeprompt or + "-artmovement-" in completeprompt or + "-malefemale-" in completeprompt or + "-objecttotal-" in completeprompt or + "-bodytype-" in completeprompt or + "-minilocation-" in completeprompt or + "-minilocationaddition-" in completeprompt or + "-pose-" in completeprompt or + "-season-" in completeprompt or + "-minioutfit-" in completeprompt or + "-elaborateoutfit-" in completeprompt or + "-minivomit-" in completeprompt or + "-vomit-" in completeprompt or + "-rpgclass-" in completeprompt or + "-subjectfromfile-" in completeprompt or + "-brand-" in completeprompt or + "-space-" in completeprompt or + "-artist-" in completeprompt or + "-imagetype-" in completeprompt or + "-othertype-" in completeprompt or + "-quality-" in completeprompt or + "-lighting-" in completeprompt or + "-camera-" in completeprompt or + "-lens-" in completeprompt or + "-imagetypequality-" in completeprompt or + "-poemline-" in completeprompt or + "-songline-" in completeprompt or + "-greatwork-" in completeprompt or + "-artistfantasy-" in completeprompt or + "-artistpopular-" in completeprompt or + "-artistromanticism-" in completeprompt or + "-artistphotography-" in completeprompt or + "-emoji-" in completeprompt or + "-timeperiod-" in completeprompt or + "-shotsize-" in completeprompt or + "-musicgenre-" in completeprompt or + "-animaladdition-" in completeprompt or + "-objectaddition-" in completeprompt or + "-humanaddition-" in completeprompt or + "-overalladdition-" in completeprompt or + "-focus-" in completeprompt or + "-direction-" in completeprompt or + "-styletilora-" in completeprompt or + "-manwomanrelation-" in completeprompt or + "-waterlocation-" in completeprompt or + "-container-" in completeprompt or + "-firstname-" in completeprompt or + "-flora-" in completeprompt): + allwildcardslistnohybrid = [ "-color-","-object-", "-animal-", "-fictional-","-nonfictional-","-building-","-vehicle-","-location-","-conceptprefix-","-food-","-haircolor-","-hairstyle-","-job-", "-accessory-", "-humanoid-", "-manwoman-", "-human-", "-colorscheme-", "-mood-", "-genderdescription-", "-artmovement-", "-malefemale-", "-bodytype-", "-minilocation-", "-minilocationaddition-", "-pose-", "-season-", "-minioutfit-", "-elaborateoutfit-", "-minivomit-", "-vomit-", "-rpgclass-", "-subjectfromfile-", "-brand-", "-space-", "-artist-", "-imagetype-", "-othertype-", "-quality-", "-lighting-", "-camera-", "-lens-","-imagetypequality-", "-poemline-", "-songline-", "-greatwork-", "-artistfantasy-", "-artistpopular-", "-artistromanticism-", "-artistphotography-", "-emoji-", "-timeperiod-", "-shotsize-", "-musicgenre-", "-animaladdition-", "-objectaddition-", "-humanaddition-", "-overalladdition-", "-focus-", "-direction-", "-styletilora-", "-manwomanrelation-", "-waterlocation-", "-container-", "-firstname-", "-flora-"] + allwildcardslistnohybridlists = [colorlist, objectlist, animallist, fictionallist, nonfictionallist, buildinglist, vehiclelist, locationlist,conceptprefixlist,foodlist,haircolorlist, hairstylelist,joblist, accessorielist, humanoidlist, manwomanlist, humanlist, colorschemelist, moodlist, genderdescriptionlist, artmovementlist, malefemalelist, bodytypelist, minilocationlist, minilocationadditionslist, poselist, seasonlist, minioutfitlist, elaborateoutfitlist, minivomitlist, vomitlist, rpgclasslist, customsubjectslist, brandlist, spacelist, artistlist, imagetypelist, othertypelist, qualitylist, lightinglist, cameralist, lenslist, imagetypequalitylist, poemlinelist, songlinelist, greatworklist, fantasyartistlist, popularartistlist, romanticismartistlist, photographyartistlist, emojilist, timeperiodlist, shotsizelist, musicgenrelist, animaladditionlist, objectadditionslist, humanadditionlist, overalladditionlist, focuslist, directionlist, stylestiloralist, manwomanrelationlist, waterlocationlist, containerlist, firstnamelist, floralist] + + allwildcardslistwithhybrid = ["-material-", "-descriptor-", "-outfit-", "-conceptsuffix-","-culture-", "-objecttotal-"] + allwildcardslistwithhybridlists = [materiallist, descriptorlist,outfitlist,conceptsuffixlist,culturelist, objecttotallist] + + + # keywordsinstring = any(word.lower() in givensubject.lower() for word in keywordslist) + for wildcard in allwildcardslistnohybrid: + attachedlist = allwildcardslistnohybridlists[allwildcardslistnohybrid.index(wildcard)] + completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,False, advancedprompting) + + + + for wildcard in allwildcardslistwithhybrid: + attachedlist = allwildcardslistwithhybridlists[allwildcardslistwithhybrid.index(wildcard)] + completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,True, advancedprompting) + + + + + # clean it up + completeprompt = cleanup(completeprompt, advancedprompting) + + + + + + return completeprompt + # function def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehybridorswap, advancedprompting): @@ -1994,7 +2435,7 @@ def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehy return completeprompt -def cleanup(completeprompt): +def cleanup(completeprompt, advancedprompting): # first, move LoRA's to the back dynamically @@ -2005,6 +2446,11 @@ def cleanup(completeprompt): completeprompt = re.sub(r"<[^>]+>", "", completeprompt) + # if we are not using advanced prompting, remove any hybrid stuff: + 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) # 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/csvfiles/hairstyles.csv b/csvfiles/hairstyles.csv index e4da2fe..49c580c 100644 --- a/csvfiles/hairstyles.csv +++ b/csvfiles/hairstyles.csv @@ -55,7 +55,7 @@ long straight Low bun Low fade Low ponytail -Lush +Lushious Man bun Mermaid waves Messy bun diff --git a/csvfiles/outfits.csv b/csvfiles/outfits.csv index 720d1da..e506528 100644 --- a/csvfiles/outfits.csv +++ b/csvfiles/outfits.csv @@ -132,6 +132,7 @@ Djellaba Dolman jacket Dolman sleeve top Doublet +Dress Dress pants Duffle coat Dzongkha diff --git a/prompttester.py b/prompttester.py index b063a0a..40eddaa 100644 --- a/prompttester.py +++ b/prompttester.py @@ -10,7 +10,7 @@ from build_dynamic_prompt import * -def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", imagetype="all",onlyartists=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender = "all", subtypeobject = "all", subtypehumanoid = "all", subtypeconcept = "all"): +def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", imagetype="all",onlyartists=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender = "all", subtypeobject = "all", subtypehumanoid = "all", subtypeconcept = "all", advancedprompting = True): loops = int(amount) # amount of images to generate steps = 0 @@ -18,7 +18,7 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im while steps < loops: # build prompt - result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept) + result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept, advancedprompting) print("") print("loop " + str(steps)) @@ -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") \ No newline at end of file +generateprompts(100,5,"all","all","all",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","",True,"",100, "all", "all", "all", "all", False) \ No newline at end of file diff --git a/promptvarianttester.py b/promptvarianttester.py new file mode 100644 index 0000000..ef1726d --- /dev/null +++ b/promptvarianttester.py @@ -0,0 +1,37 @@ +import sys, os +import random +import uuid +import re +from datetime import datetime +sys.path.append(os.path.abspath("..")) + + +from build_dynamic_prompt import * + + + +def generatepromptvariants(amount = 1,prompt="",insanitylevel="5"): + loops = int(amount) # amount of images to generate + steps = 0 + + insanitylevel = int(insanitylevel) + while steps < loops: + # build prompt + promptnew = build_dynamic_prompt(insanitylevel) + + result = createpromptvariant(promptnew, insanitylevel) + + print(result) + + print("") + print("loop " + str(steps)) + print("") + + + steps += 1 + + + 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 From a0d2d31faeda3bf8bfd52dae517a8b967f840a6f Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 4 Aug 2023 09:14:23 +0200 Subject: [PATCH 3/8] Improvements + new node build! --- OneButtonPrompt-node.py | 54 +++++- build_dynamic_prompt.py | 387 ++++++++++++++++++++----------------- main.py | 8 +- prompttester.py | 2 +- promptvarianttester.py | 7 +- scripts/onebuttonprompt.py | 14 +- 6 files changed, 276 insertions(+), 196 deletions(-) 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): From b02e5638b866cde1eb221250ff23c598468a1796 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 4 Aug 2023 20:49:34 +0200 Subject: [PATCH 4/8] added save prompt node for comfyUI --- OneButtonPrompt-node.py | 84 ++++++++++++++++++++++++++++++++++++++++- build_dynamic_prompt.py | 12 ++++-- promptvarianttester.py | 2 +- 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/OneButtonPrompt-node.py b/OneButtonPrompt-node.py index 675415e..78f30b5 100644 --- a/OneButtonPrompt-node.py +++ b/OneButtonPrompt-node.py @@ -1,5 +1,8 @@ import sys import os +import folder_paths +from datetime import datetime +import uuid # adding Folder_2/subfolder to the system path # sys.path.insert(0, '/home/amninder/Desktop/project/Folder_2/subfolder') @@ -115,16 +118,93 @@ class CreatePromptVariant: return (generatedprompt,) +# Let us create our own prompt saver. Not everyone has WAS installed +class SavePromptToFile: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "positive_prompt": ("STRING",{"multiline": True}), + "negative_prompt": ("STRING",{"multiline": True}), + }, + } + + OUTPUT_NODE = True + RETURN_TYPES = () + FUNCTION = "saveprompttofile" + + CATEGORY = "OneButtonPrompt" + + def saveprompttofile(self, positive_prompt, negative_prompt): + + # make the filename, from from a to the first comma + # find the index of the first comma after "of a" or end of the prompt + if(positive_prompt.find("of a ") != -1): + start_index = positive_prompt.find("of a ") + len("of a ") + end_index = positive_prompt.find(",", start_index) + if(end_index == -1): + end_index=len(positive_prompt) + else: + start_index = 0 + end_index = 128 + + + + # extract the desired substring using slicing + filename = positive_prompt[start_index:end_index] + + # cleanup some unsafe things in the filename + filename = filename.replace("\"", "") + filename = filename.replace("[", "") + filename = filename.replace("|", "") + filename = filename.replace("]", "") + filename = filename.replace("<", "") + filename = filename.replace(">", "") + filename = filename.replace(":", "_") + filename = re.sub(r'[0-9]+', '', filename) + + safe_characters = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.") + + # Use regular expression to filter out any characters not in the whitelist + filename = re.sub(r"[^{}]+".format(re.escape(''.join(safe_characters))), '', filename) + + + if(filename==""): + filename = str(uuid.uuid4()) + + # create a datetime object for the current date and time + now = datetime.now() + filenamecomplete = now.strftime("%Y%m%d%H%M%S") + "_" + filename.replace(" ", "_").strip() + ".txt" + + + # Get the output folder from comfy + output_directory = folder_paths.output_directory + + directoryandfilename = os.path.abspath(os.path.join(output_directory, filenamecomplete)) + + + with open(directoryandfilename, 'w') as file: + file.write("prompt: " + positive_prompt + "\n") + file.write("negative prompt: " + negative_prompt + "\n") + + + + return ("done") # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "OneButtonPrompt": OneButtonPrompt, - "CreatePromptVariant": CreatePromptVariant + "CreatePromptVariant": CreatePromptVariant, + "SavePromptToFile": SavePromptToFile } # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { "OneButtonPrompt": "One Button Prompt", - "CreatePromptVariant": "Create Prompt Variant" + "CreatePromptVariant": "Create Prompt Variant", + "SavePromptToFile": "Save Prompt To File" } diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index e41349f..516eb71 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -2197,7 +2197,6 @@ def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender 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- ") @@ -2207,11 +2206,9 @@ def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender 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- ") @@ -2300,15 +2297,22 @@ def createpromptvariant(prompt = "", insanitylevel = 5, antivalues = "" , gender 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 stylestiloralist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -styletilora- ") + if lowercase_combination in [x.lower() for x in waterlocationlist] and chance_roll(insanitylevel, "uncommon"): + prompt = prompt.replace(combination," -waterlocation- ") + runs += 1 - + prompt = prompt.replace(" :", ":") + prompt = prompt.replace(": ", ":") completeprompt = prompt + while ( "-color-" in completeprompt or "-material-" in completeprompt or diff --git a/promptvarianttester.py b/promptvarianttester.py index ac5d4b7..b67e7d3 100644 --- a/promptvarianttester.py +++ b/promptvarianttester.py @@ -35,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, -artmovement-", 0) \ No newline at end of file +generatepromptvariants(1,"purple (galaxy) in a (bottle:1.2), , background is a lush jungle and a woman wearing a summer dress, -artmovement-", 5) \ No newline at end of file From dd28375367fe5a2fbcf6454b0183fb7bcf6e2ec3 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 4 Aug 2023 21:21:03 +0200 Subject: [PATCH 5/8] Renaming and moving stuff around so install can be done easy in ComfyUI --- OneButtonPrompt-node.py => OneButtonPromptNodes.py | 2 +- __init__.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) rename OneButtonPrompt-node.py => OneButtonPromptNodes.py (99%) create mode 100644 __init__.py diff --git a/OneButtonPrompt-node.py b/OneButtonPromptNodes.py similarity index 99% rename from OneButtonPrompt-node.py rename to OneButtonPromptNodes.py index 78f30b5..c0fe8a5 100644 --- a/OneButtonPrompt-node.py +++ b/OneButtonPromptNodes.py @@ -186,7 +186,7 @@ class SavePromptToFile: directoryandfilename = os.path.abspath(os.path.join(output_directory, filenamecomplete)) - with open(directoryandfilename, 'w') as file: + with open(directoryandfilename, 'w', encoding="utf-8") as file: file.write("prompt: " + positive_prompt + "\n") file.write("negative prompt: " + negative_prompt + "\n") diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..206c4c1 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from .OneButtonPromptNodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file From 9fbbaa91ac874706322743684b84f2a688bdfd5d Mon Sep 17 00:00:00 2001 From: AIrjen <130234949+AIrjen@users.noreply.github.com> Date: Fri, 4 Aug 2023 22:07:02 +0200 Subject: [PATCH 6/8] Update comfyui_integration.md --- user_guides/comfyui_integration.md | 50 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/user_guides/comfyui_integration.md b/user_guides/comfyui_integration.md index 60eb89a..37b2a41 100644 --- a/user_guides/comfyui_integration.md +++ b/user_guides/comfyui_integration.md @@ -1,7 +1,7 @@ # ComfyUI integration -In this codebase there is a custom node, that can be used in ComfyUI. -Work is still in progress for all features to work flawlessly in ComfyUI, but a start has been made. +One Button Prompt is now also a ComfyUI extension. +There are 3 nodes currently availabe, with One Button Prompt node being the main one. You can slam it in every workflow, where you replace it with the Positive Prompt node. ![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/a9c6b449-772b-495c-b39d-eda0be38a203) @@ -9,32 +9,44 @@ You can slam it in every workflow, where you replace it with the Positive Prompt ## Installing in ComfyUI -Navigate to your ComfyUI directory, and run the following command: +Navigate to your ComfyUI\custom_nodes\ directory, and run the following command: ``` git clone https://github.com/AIrjen/OneButtonPrompt ``` -This should create a OneButtonPrompt directory in the ComfyUI folder. +This should create a OneButtonPrompt directory in the ComfyUI\custom_nodes\ folder. -![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/5d9cfdd3-8342-4aff-a9a4-ecbbc7151856) +It could like something like this -From this folder, manually copy the file -``` -OneButtonPrompt-node.py -``` - -Into the ComfyUI\custom_nodes\ folder. -That should look like this: - -![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/f2c9630e-790b-4a34-b46f-54dbb18b87d5) +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/50f9d8b4-dd0a-4c87-b8c4-25a159c71d75) After that, restart ComfyUI, and you are ready to go. +It should be available in ComfyUI manager soonish as well. + +## Custom nodes + +### One Button Prompt + +### Create Prompt Variant +You can use the "Create Prompt Variant" node, to create variants based on a prompt you input. The strength of the variant is set with the "insanity level" slider. Simply connect it between the positive prompt and the CLIP encoder module. + +It will automatically create a small variance in the prompt, based on magic. It might not work for every prompt. + +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/a0191a18-eac9-4261-ab26-4dfdd997dad0) + +Here is an example of ComfyUI standard prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," + +These are all generated with the same model, same settings, same seed. But some of these have the Create Prompt Variant node included. + +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/dfe7fc06-face-4949-a048-d310504d3c3c) + +Here is an example of the entire example workflow. + +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/117fc612-5a7d-4b0d-b163-adf8ff84555c) + + ### Known issues -1. ComfyUI does NOT store the prompt in the image, but the workflow. Since the prompt is not in the workflow, it is not saved. I am unsure wether there is a custom node for this. -2. There is a SEED option in the One Button Prompt node, this is a hacky thing. It is just there to make sure it is refired each time you generate an image. -3. Prompts are styled for Automatic1111, so it uses prompt switching, which is not supported by ComfyUI. -4. Easy installer not yet available. +1. There is a SEED option in the One Button Prompt node, this is a hacky thing. It is just there to make sure it is refired each time you generate an image. -Issues will be investigated over time. From 6697c958b3bb75edce361bc0e0dbb0cea12ad22b Mon Sep 17 00:00:00 2001 From: AIrjen <130234949+AIrjen@users.noreply.github.com> Date: Fri, 4 Aug 2023 22:13:31 +0200 Subject: [PATCH 7/8] Update comfyui_integration.md --- user_guides/comfyui_integration.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/user_guides/comfyui_integration.md b/user_guides/comfyui_integration.md index 37b2a41..4d8bc5f 100644 --- a/user_guides/comfyui_integration.md +++ b/user_guides/comfyui_integration.md @@ -28,6 +28,10 @@ It should be available in ComfyUI manager soonish as well. ### One Button Prompt +All settings work similar to the settings in the Automatic1111 documentation. + +It will generate a prompt from scratch, or based on several of your inputs and settings. + ### Create Prompt Variant You can use the "Create Prompt Variant" node, to create variants based on a prompt you input. The strength of the variant is set with the "insanity level" slider. Simply connect it between the positive prompt and the CLIP encoder module. @@ -45,6 +49,16 @@ Here is an example of the entire example workflow. ![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/117fc612-5a7d-4b0d-b163-adf8ff84555c) +### Save Prompt To File + +Use the Save Prompt To File node to actually save the prompt in a text file. Since ComfyUI stores the entire flow in the image, it doesn't store the actual generated prompt. + +You can also use other extension for this. But I thought it was nice to include a save options nativly. There are other options out there as well. + +Just simply also connect the output of One Button Prompt to the Postive Prompt node. + +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/1557546d-36f3-4ce0-9532-cf5a8386297d) + ### Known issues From ac2f86b883c31a13a5b5628ae5c8354b4d47cf79 Mon Sep 17 00:00:00 2001 From: AIrjen <130234949+AIrjen@users.noreply.github.com> Date: Fri, 4 Aug 2023 22:15:08 +0200 Subject: [PATCH 8/8] Update comfyui_integration.md --- user_guides/comfyui_integration.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guides/comfyui_integration.md b/user_guides/comfyui_integration.md index 4d8bc5f..88d13fb 100644 --- a/user_guides/comfyui_integration.md +++ b/user_guides/comfyui_integration.md @@ -32,6 +32,10 @@ All settings work similar to the settings in the Automatic1111 documentation. It will generate a prompt from scratch, or based on several of your inputs and settings. +![image](https://github.com/AIrjen/OneButtonPrompt/assets/130234949/bca84637-a667-48e4-888d-9b0318eb4f43) + +Please refer to the other documentation to see what each setting does. + ### Create Prompt Variant You can use the "Create Prompt Variant" node, to create variants based on a prompt you input. The strength of the variant is set with the "insanity level" slider. Simply connect it between the positive prompt and the CLIP encoder module.