diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 6bb2a3f..240b65a 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -92,29 +92,164 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all custominputsuffixlist = csv_to_list("custom_input_suffix",antilist,"./userfiles/") generatecustominputsuffix = bool(custominputsuffixlist) # True of not empty + # 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/") - generateoutfit = True - generatebodytype = True - generateaccesorie = True - generateartmovement = True - generatebackground = True - generatecamera = True - generatecolorscheme = True - generatedescriptors = True - generatedirection = True - generatefocus = True - generatehairstyle = True - generatelens = True - generatelighting = True - generatemood = True - generatepose = True - generatevomit = True - generatequality = True - generateshot = True - generatetimeperiod = True + + + + # subjects + mainchooserlist = [] + objectwildcardlist = [] + hybridlist = [] + hybridhumanlist = [] + humanoidsubjectchooserlist = [] + eventsubjectchooserlist = [] + addontolocationinside = [] + addontolocation = [] + + generatevehicle = bool(vehiclelist) + generateobject = bool(objectlist) + generatefood = bool(foodlist) + generatebuilding = bool(buildinglist) + generateobject = generatevehicle + generateobject + generatefood + generatebuilding + + if(generatevehicle): + objectwildcardlist.append("-vehicle-") + hybridlist.append("-vehicle-") + addontolocation.append(vehiclelist) + + if(generateobject): + objectwildcardlist.append("-object-") + hybridlist.append("-object-") + + if(generatefood): + objectwildcardlist.append("-food-") + hybridlist.append("-food-") + + if(generatebuilding): + objectwildcardlist.append("-building-") + hybridlist.append("-building-") + addontolocation.append(buildinglist) + addontolocationinside.append(buildinglist) + + if(generateobject): + mainchooserlist.append("object") + + generatefictionalcharacter = bool(fictionallist) + generatenonfictionalcharacter = bool(nonfictionallist) + generatehumanoids = bool(humanoidlist) + generatemanwoman = bool(manwomanlist) + generatejob = bool(joblist) + generatehumanoid = generatefictionalcharacter + generatenonfictionalcharacter + generatehumanoids + generatemanwoman + generatejob + + + if(generatefictionalcharacter): + humanoidsubjectchooserlist.append("fictional") + hybridlist.append("-fictional-") + hybridhumanlist.append("-fictional-") + + if(generatefictionalcharacter): + humanoidsubjectchooserlist.append("non fictional") + hybridlist.append("-nonfictional-") + hybridhumanlist.append("-nonfictional-") + + if(generatehumanoids): + humanoidsubjectchooserlist.append("humanoid") + hybridlist.append("-humanoid-") + hybridhumanlist.append("-humanoid-") + + if(generatemanwoman): + humanoidsubjectchooserlist.append("human") + + if(generatejob): + humanoidsubjectchooserlist.append("job") + + if(generatehumanoid): + mainchooserlist.append("humanoid") + + + generateanimal = bool(animallist) + + if(generateanimal): + mainchooserlist.append("animal") + hybridlist.append("-animal-") + + generatelandscape = bool(locationlist) + + if(generatelandscape): + mainchooserlist.append("landscape") + addontolocation.append(locationlist) + addontolocationinside.append(locationlist) + + generateevent = bool(eventlist) + generateconcepts = bool(conceptprefixlist) + bool(conceptsuffixlist) + + generateconcept = generateevent + generateconcepts + + if(generateevent): + eventsubjectchooserlist.append("event") + + if(generateconcepts): + eventsubjectchooserlist.append("concept") + + if(generateconcept): + mainchooserlist.append("concept") + + + + + + #mainchooserlist = ["object","animal","humanoid", "landscape", "concept"] + #objectwildcardlist = ["-object-", "-building-","-vehicle-","-food-"] # using wildcards for replacements + #hybridlist = ["-animal-", "-object-", "-fictional-", "-nonfictional-", "-building-", "-vehicle-","-food-"] + #humanoidsubjectchooserlist = ["human", "job", "fictional", "non fictional", "humanoid"] + #eventsubjectchooserlist = ["event", "concept"] + + + + # normals + generateoutfit = bool(outfitlist) + generatebodytype = bool(bodytypelist) + generateaccessorie = bool(accessorielist) + generateartmovement = bool(artmovementlist) + generatecamera = bool(cameralist) + generatecolorscheme = bool(colorschemelist) + generatedescriptors = bool(descriptorlist) + generatedirection = bool(directionlist) + generatefocus = bool(focuslist) + generatehairstyle = bool(hairstylelist) + generatelens = bool(lenslist) + generatelighting = bool(lightinglist) + generatemood = bool(moodlist) + generatepose = bool(poselist) + generatevomit = bool(vomitlist) + generatequality = bool(qualitylist) + generateshot = bool(shotsizelist) + generatetimeperiod = bool(timeperiodlist) + generateemoji = bool(emojilist) + + # specials: + generatebackground = bool(backgroundtypelist) + generateinsideshot = bool(insideshotlist) + generatephotoaddition = bool(photoadditionlist) + generatehairstyle = bool(buildhairlist) + generateoutfit = bool(buildoutfitlist) + generateobjectaddition = bool(objectadditionslist) + generatehumanaddition = bool(humanadditionlist) + generateanimaladdition = bool(animaladditionlist) + generateaccessories = bool(buildaccessorielist) # Smart subject logic - if(givensubject !="" and smartsubject == True): + if(givensubject != "" and smartsubject == True): # Remove any list that has a matching word in the list # Remove any list/logic with keywords, such as: @@ -179,15 +314,16 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # background foundinlist = any(word.lower() in [item.lower() for item in locationlist] for word in givensubjectlist) foundinlist2 = any(word.lower() in [item.lower() for item in buildinglist] for word in givensubjectlist) - keywordslist = ["location","background"] + keywordslist = ["location","background", "inside"] keywordsinstring = any(word.lower() in givensubject.lower() for word in keywordslist) if(foundinlist == True or foundinlist2 == True or keywordsinstring == True): generatebackground = False + generateinsideshot = False # accessorielist foundinlist = any(word.lower() in [item.lower() for item in accessorielist] for word in givensubjectlist) if(foundinlist == True): - generateaccesorie = False + generateaccessorie = False # lenslist foundinlist = any(word.lower() in [item.lower() for item in lenslist] for word in givensubjectlist) @@ -295,9 +431,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # custom prefix list - if(uncommon_dist(insanitylevel) and generatecustominputprefix == True): - completeprompt += random.choice(custominputprefixlist) + ", " - if(uncommon_dist(insanitylevel)): + for i in range(2): + if(uncommon_dist(insanitylevel) and generatecustominputprefix == True): completeprompt += random.choice(custominputprefixlist) + ", " @@ -309,8 +444,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all print("Setting insanity level to " + str(insanitylevel)) # main chooser: 0 object, 1 animal, 2 humanoid, 3 landscape, 4 event/concept - mainchooserlist = ["object","animal","humanoid", "landscape", "concept"] - mainchooser = mainchooserlist[random.randint(0, 4)] + #mainchooserlist = ["object","animal","humanoid", "landscape", "concept"] + mainchooser = random.choice(mainchooserlist) if(forcesubject != "" and forcesubject != "all"): mainchooser = forcesubject @@ -324,17 +459,17 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all else: subjectchooser = "animal as human" if(mainchooser == "humanoid"): - subjectchooserlist = ["human", "job", "fictional", "non fictional", "humanoid"] - subjectchooser = subjectchooserlist[random.randint(0, 4)] + #humanoidsubjectchooserlist = ["human", "job", "fictional", "non fictional", "humanoid"] + subjectchooser = random.choice(humanoidsubjectchooserlist) if(mainchooser == "landscape"): subjectchooser = "landscape" if(mainchooser == "concept"): - subjectchooserlist = ["event", "concept"] - subjectchooser = subjectchooserlist[random.randint(0, 1)] + #eventsubjectchooserlist = ["event", "concept"] + subjectchooser = random.choice(eventsubjectchooserlist) - hybridlist = ["-animal-", "-object-", "-fictional-", "-nonfictional-", "-building-", "-vehicle-","-food-"] - hybridhumanlist = ["-fictional-", "-nonfictional-"] + #hybridlist = ["-animal-", "-object-", "-fictional-", "-nonfictional-", "-building-", "-vehicle-","-food-"] + #hybridhumanlist = ["-fictional-", "-nonfictional-"] # start artist part @@ -409,7 +544,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if artistmode in ["switching","adding"]: completeprompt += ":" + str(random.randint(1,18)) if artistmode in ["hybrid", "stopping","adding", "switching"]: - completeprompt += "]" + completeprompt += "] " if(onlyartists == True): @@ -484,7 +619,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(culturelist) + " " if(mainchooser == "object"): - objecttypelist = [objectlist, buildinglist, vehiclelist, foodlist] # first select a random list, then randomly select from the corresponding list + # objectwildcardlist = ["-object-", "-building-","-vehicle-","-food-"] # using wildcards for replacements # if we have a given subject, we should skip making an actual subject if(givensubject == ""): @@ -494,24 +629,24 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" - chosenobjecttype = random.choice(objecttypelist) + chosenobjectwildcard = random.choice(objectwildcardlist) - completeprompt += random.choice(chosenobjecttype) + " " + completeprompt += chosenobjectwildcard + " " if(hybridorswap == "hybrid"): if(uncommon_dist(insanitylevel)): - completeprompt += "|" + random.choice(hybridlist) + "]" + completeprompt += "|" + random.choice(hybridlist) + "] " else: completeprompt += "|" - completeprompt += random.choice(chosenobjecttype) + " " - completeprompt += "]" + completeprompt += random.choice(chosenobjectwildcard) + " " + completeprompt += "] " if(hybridorswap == "swap"): if(uncommon_dist(insanitylevel)): - completeprompt += ":" + random.choice(hybridlist) + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + random.choice(hybridlist) + ":" + str(random.randint(1,5)) + "] " else: completeprompt += ":" - completeprompt += random.choice(chosenobjecttype) + " " - completeprompt += ":" + str(random.randint(1,5)) + "]" + completeprompt += chosenobjectwildcard + " " + completeprompt += ":" + str(random.randint(1,5)) + "] " else: completeprompt += " " + givensubject + " " @@ -527,23 +662,22 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all hybridorswap = random.choice(hybridorswaplist) completeprompt += "[" - if unique_dist(insanitylevel): - animaladdlist = ["baby", "were", "giant", "monster"] + if(unique_dist(insanitylevel) and generateanimaladdition == True): animaladdedsomething = 1 - completeprompt += random.choice(animaladdlist) + " -animal-" + completeprompt += random.choice(animaladditionlist) + " -animal- " if(animaladdedsomething != 1): completeprompt += random.choice(animallist) + " " if(hybridorswap == "hybrid"): if(uncommon_dist(insanitylevel)): - completeprompt += "|" + random.choice(hybridlist) + "]" + completeprompt += "|" + random.choice(hybridlist) + "] " else: - completeprompt += "| -animal- ]" + completeprompt += "| -animal- ] " if(hybridorswap == "swap"): if(uncommon_dist(insanitylevel)): - completeprompt += ":" + random.choice(hybridlist) + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + random.choice(hybridlist) + ":" + str(random.randint(1,5)) + "] " else: - completeprompt += ":-animal-:" + str(random.randint(1,5)) + "]" + completeprompt += ":-animal-:" + str(random.randint(1,5)) + "] " else: completeprompt += " " + givensubject + " " @@ -569,9 +703,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(fictionallist) + " " if(hybridorswap == "hybrid"): - completeprompt += "|" + random.choice(hybridhumanlist) + "]" + completeprompt += "|" + random.choice(hybridhumanlist) + " ] " if(hybridorswap == "swap"): - completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "] " hybridorswap = "" if(subjectchooser == "non fictional"): @@ -583,9 +717,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(nonfictionallist) + " " if(hybridorswap == "hybrid"): - completeprompt += "|" + random.choice(hybridhumanlist) + "]" + completeprompt += "|" + random.choice(hybridhumanlist) + "] " if(hybridorswap == "swap"): - completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "] " hybridorswap = "" if(subjectchooser == "humanoid"): @@ -597,9 +731,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(humanoidlist) + " " if(hybridorswap == "hybrid"): - completeprompt += "|" + random.choice(hybridhumanlist) + "]" + completeprompt += "|" + random.choice(hybridhumanlist) + "] " if(hybridorswap == "swap"): - completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + random.choice(hybridhumanlist) + ":" + str(random.randint(1,5)) + "] " hybridorswap = "" else: completeprompt += " " + givensubject + " " @@ -617,9 +751,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(locationlist) + " " if(hybridorswap == "hybrid"): - completeprompt += "|" + "-location-" + "]" + completeprompt += "|" + "-location-" + "] " if(hybridorswap == "swap"): - completeprompt += ":" + "-location-" + ":" + str(random.randint(1,5)) + "]" + completeprompt += ":" + "-location-" + ":" + str(random.randint(1,5)) + "] " else: completeprompt += " " + givensubject + " " @@ -629,8 +763,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if(unique_dist(insanitylevel)): insideshot = 1 completeprompt += " from inside of a " - addontolocation = [locationlist,buildinglist] - completeprompt += random.choice(random.choice(addontolocation)) + " " + #addontolocationinside = [locationlist,buildinglist] + completeprompt += random.choice(random.choice(addontolocationinside)) + " " if(normal_dist(insanitylevel) and insideshot == 0): completeprompt += " and " @@ -639,7 +773,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if(rare_dist(insanitylevel)): completeprompt += random.choice(culturelist) + " " - addontolocation = [locationlist,buildinglist, vehiclelist] + #addontolocation = [locationlist,buildinglist, vehiclelist] completeprompt += random.choice(random.choice(addontolocation)) + " " @@ -649,45 +783,32 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += " \"" + random.choice(eventlist) + "\" " if(subjectchooser == "concept"): - completeprompt += " \" The " + random.choice(conceptprefixlist) + " of " + random.choice(conceptsuffixlist) + "\" " + completeprompt += " \" The -conceptprefix- of -conceptsuffix- \" " else: completeprompt += " " + givensubject + " " - # object with a face - if(mainchooser == "object" and unique_dist(insanitylevel)): - completeprompt += " with a face " - - # object materials - if(mainchooser == "object" and uncommon_dist(insanitylevel)): - completeprompt += " made from -material- " - - # object detailing - if(mainchooser == "object" and rare_dist(insanitylevel)): - completeprompt += " detailed with " - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(descriptorlist) + " " - completeprompt += "-material- patterns " - + # object additions + for i in range(2): + if(mainchooser == "object" and uncommon_dist(insanitylevel) and generateobjectaddition == True): + completeprompt += random.choice(objectadditionslist) + ", " + # riding an animal, holding an object or driving a vehicle, rare - if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and rare_dist(insanitylevel)): + if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and rare_dist(insanitylevel) and generatehumanaddition == True): humanspecial = 1 - speciallist = [" riding a -animal- ", " holding a -object- ", " driving a -vehicle-", " visiting a -building-", " with a -animal-", " surrounded by -object-s", " eating -food-"] - completeprompt += random.choice(speciallist) + completeprompt += random.choice(humanadditionlist) + " " - - completeprompt += ", " # SD understands emoji's. Can be used to manipulate facial expressions. # emoji, legendary - if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and legendary_dist(insanitylevel)): + if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and legendary_dist(insanitylevel) and generateemoji== True): completeprompt += random.choice(emojilist) + ", " # cosplaying - if(subjectchooser in ["animal as human", "non fictional", "humanoid"] and rare_dist(insanitylevel) and humanspecial != 1): - completeprompt += "cosplaying as " + random.choice(fictionallist) + ", " + #if(subjectchooser in ["animal as human", "non fictional", "humanoid"] and rare_dist(insanitylevel) and humanspecial != 1): + # completeprompt += "cosplaying as " + random.choice(fictionallist) + ", " # Job # either go job or activity, not both @@ -697,9 +818,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(random.choice(joboractivitylist)) + ", " - if(subjectchooser in ["animal as human","human","job", "fictional", "non fictional", "humanoid"] and legendary_dist(insanitylevel)): - skintypelist = ["-color-", "-material-"] - completeprompt += ", with " + random.choice(skintypelist) + " skin, " + # if(subjectchooser in ["animal as human","human","job", "fictional", "non fictional", "humanoid"] and legendary_dist(insanitylevel)): + # skintypelist = ["-color-", "-material-"] + # completeprompt += ", with " + random.choice(skintypelist) + " skin, " # custom mid list if(uncommon_dist(insanitylevel) and generatecustominputmid == True): @@ -710,69 +831,24 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all # outfit builder if(subjectchooser in ["animal as human","human","fictional", "non fictional", "humanoid"] and normal_dist(insanitylevel) and generateoutfit == True): - completeprompt += ", wearing " - if(normal_dist(insanitylevel)): - completeprompt += random.choice(descriptorlist) + " " - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(culturelist) + " " - if(normal_dist(insanitylevel)): - completeprompt += " -color- " - if(rare_dist(insanitylevel)): - completeprompt += " -material- " - - if rare_dist(insanitylevel): - hybridorswaplist = ["hybrid", "swap"] - hybridorswap = random.choice(hybridorswaplist) - completeprompt += "[" - - completeprompt += random.choice(outfitlist) + " " - - if(hybridorswap == "hybrid"): - completeprompt += "|" + "-outfit-" + "]" - if(hybridorswap == "swap"): - completeprompt += ":" + "-outfit-" + ":" + str(random.randint(1,5)) + "]" - hybridorswap = "" - completeprompt += ", " - + completeprompt += ", wearing " + random.choice(buildoutfitlist) + ", " if(subjectchooser in ["animal as human","human","fictional", "non fictional", "humanoid"] and uncommon_dist(insanitylevel) and humanspecial != 1 and generatepose == True): completeprompt += random.choice(poselist) + ", " if(subjectchooser in ["human","job","fictional", "non fictional", "humanoid"] and normal_dist(insanitylevel) and generatehairstyle == True): - completeprompt += random.choice(haircolorlist) + " " - completeprompt += " hair styled as " + random.choice(hairstylelist) + ", " + completeprompt += random.choice(buildhairlist) + ", " - if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and normal_dist(insanitylevel) and generateaccesorie == True): - completeprompt += random.choice(accessorielist) + ", " - # Sometimes get 2 - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(accessorielist) + ", " - # or even three, these are fun and often minor :) - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(accessorielist) + ", " + if(subjectchooser in ["animal as human,","human","fictional", "non fictional", "humanoid"] and normal_dist(insanitylevel) and generateaccessorie == True and generateaccessories == True): + completeprompt += random.choice(buildaccessorielist) + ", " - if(legendary_dist(insanitylevel) and subjectchooser not in ["landscape", "concept"] and generatebackground == True): + if(legendary_dist(insanitylevel) and subjectchooser not in ["landscape", "concept"] and generateinsideshot == True): insideshot = 1 - completeprompt += ", from inside of a " - addontolocation = [locationlist,buildinglist] - completeprompt += random.choice(random.choice(addontolocation)) + ", " + completeprompt += random.choice(insideshotlist) + ", " if(subjectchooser not in ["landscape", "concept"] and humanspecial != 1 and insideshot == 0 and uncommon_dist(insanitylevel) and generatebackground == True): - backgroundtypelist = ["landscape", "buildingbackground", "insidebuilding"] - backgroundtype = random.choice(backgroundtypelist) - if(backgroundtype == "landscape"): - completeprompt += "background is " + random.choice(locationlist) + ", " - elif(backgroundtype == "buildingbackground"): - completeprompt += ", background is " - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(descriptorlist) + " " - completeprompt += random.choice(buildinglist) + ", " - elif(backgroundtype == "insidebuilding"): - completeprompt += ", inside a " - if(uncommon_dist(insanitylevel)): - completeprompt += random.choice(descriptorlist) + " " - completeprompt += random.choice(buildinglist) + ", " - + completeprompt += random.choice(backgroundtypelist) + ", " + @@ -801,10 +877,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += random.choice(lightinglist) + ", " # determine wether we have a photo or not - if("hoto" in completeprompt): + if("photo" in completeprompt.lower()): isphoto = 1 - if(common_dist(insanitylevel) and not "film grain" in antilist): - completeprompt += ", film grain, " + + if(common_dist(insanitylevel) and isphoto == 1 and generatephotoaddition == True): + completeprompt += random.choice(photoadditionlist) + ", " if(isphoto == 1 and generatecamera == True): completeprompt += random.choice(cameralist) + ", " @@ -848,7 +925,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if artistmode in ["enhancing"]: - completeprompt += "::" + str(random.randint(1,17)) + "]" + completeprompt += "::" + str(random.randint(1,17)) + "] " @@ -911,7 +988,7 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if artistmode in ["switching","adding"]: completeprompt += ":" + str(random.randint(1,18)) if artistmode in ["hybrid", "stopping","adding", "switching"]: - completeprompt += "]" + completeprompt += "] " # end of the artist stuff @@ -933,51 +1010,45 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all #end of the while loop, now clean up the prompt + + # first some manual stuff for outfit + + if(unique_dist(insanitylevel)): # sometimes, its just nice to have descriptor and a normal "outfit" + completeprompt = completeprompt.replace('-outfit-', 'outfit',1) + + # do the hybrid/swap thing in here instead + # if(rare_dist(insanitylevel)): + # hybridorswaplist = ["hybrid", "swap"] + # hybridorswap = random.choice(hybridorswaplist) + # hybridorswapreplacementvalue = "[" + random.choice(outfitlist) + # + # if(hybridorswap == "hybrid"): + # hybridorswapreplacementvalue += "|" + random.choice(outfitlist) + "] " + # if(hybridorswap == "swap"): + # if(uncommon_dist(insanitylevel)): + # hybridorswapreplacementvalue += ":" + random.choice(outfitlist) + ":" + str(random.randint(1,20)) + "] " + # + # completeprompt = completeprompt.replace('-outfit-', hybridorswapreplacementvalue,1) # lol, this needs a rewrite :D - 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: - while "-object-" in completeprompt: - completeprompt = completeprompt.replace('-object-', random.choice(objectlist),1) - - while "-location-" in completeprompt: - completeprompt = completeprompt.replace('-location-', random.choice(locationlist),1) - - while "-outfit-" in completeprompt: - completeprompt = completeprompt.replace('-outfit-', random.choice(outfitlist),1) + 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: + allwildcardslistnohybrid = [ "-color-","-object-", "-animal-", "-fictional-","-nonfictional-","-building-","-vehicle-","-location-","-conceptprefix-","-food-","-haircolor-","-hairstyle-","-job-", "-accessory-", "-humanoid-" ] + allwildcardslistnohybridlists = [colorlist, objectlist, animallist, fictionallist, nonfictionallist, buildinglist, vehiclelist, locationlist,conceptprefixlist,foodlist,haircolorlist, hairstylelist,joblist, accessorielist, humanoidlist] + allwildcardslistwithhybrid = ["-material-", "-descriptor-", "-outfit-", "-conceptsuffix-","-culture-"] + allwildcardslistwithhybridlists =[materiallist, descriptorlist,outfitlist,conceptsuffixlist,culturelist] - while "-building-" in completeprompt: - completeprompt = completeprompt.replace('-building-', random.choice(buildinglist),1) + # 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) - while "-vehicle-" in completeprompt: - completeprompt = completeprompt.replace('-vehicle-', random.choice(vehiclelist),1) - while "-conceptsuffix-" in completeprompt: - completeprompt = completeprompt.replace('-conceptsuffix-', random.choice(conceptsuffixlist),1) - - while "-color-" in completeprompt: - completeprompt = completeprompt.replace('-color-', random.choice(colorlist),1) + for wildcard in allwildcardslistwithhybrid: + attachedlist = allwildcardslistwithhybridlists[allwildcardslistwithhybrid.index(wildcard)] + completeprompt = replacewildcard(completeprompt, insanitylevel, wildcard, attachedlist,True) - while "-material-" in completeprompt: - completeprompt = completeprompt.replace('-material-', random.choice(materiallist),1) - - while "-fictional-" in completeprompt: - completeprompt = completeprompt.replace('-fictional-', random.choice(fictionallist),1) - - while "-nonfictional-" in completeprompt: - completeprompt = completeprompt.replace('-nonfictional-', random.choice(nonfictionallist),1) - while "-animal-" in completeprompt: - completeprompt = completeprompt.replace('-animal-', random.choice(animallist),1) - while "-conceptprefix-" in completeprompt: - completeprompt = completeprompt.replace('-conceptprefix-', random.choice(conceptprefixlist),1) - - while "-descriptor-" in completeprompt: - completeprompt = completeprompt.replace('-descriptor-', random.choice(descriptorlist),1) - - while "-food-" in completeprompt: - completeprompt = completeprompt.replace('-food-', random.choice(foodlist),1) - @@ -1015,4 +1086,29 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all print(completeprompt) return completeprompt - \ No newline at end of file + + + # function +def replacewildcard(completeprompt, insanitylevel, wildcard,listname, activatehybridorswap): + if(len(listname) == 0): + # handling empty lists + completeprompt = completeprompt.replace(wildcard, "",1) + else: + + while wildcard in completeprompt: + if(unique_dist(insanitylevel) and activatehybridorswap == True): + hybridorswaplist = ["hybrid", "swap"] + hybridorswap = random.choice(hybridorswaplist) + hybridorswapreplacementvalue = "[" + random.choice(listname) + + if(hybridorswap == "hybrid"): + hybridorswapreplacementvalue += "|" + random.choice(listname) + "] " + if(hybridorswap == "swap"): + if(uncommon_dist(insanitylevel)): + hybridorswapreplacementvalue += ":" + random.choice(listname) + ":" + str(random.randint(1,20)) + "] " + + completeprompt = completeprompt.replace(wildcard, hybridorswapreplacementvalue,1) + + completeprompt = completeprompt.replace(wildcard, random.choice(listname),1) + + return completeprompt \ No newline at end of file diff --git a/csv_reader.py b/csv_reader.py index 14056c2..afec379 100644 --- a/csv_reader.py +++ b/csv_reader.py @@ -27,7 +27,7 @@ def csv_to_list(csvfilename, antilist=[], directory="./csvfiles/", lowerandstrip full_path = os.path.join(script_dir, directory ) userfilesfolder = os.path.join(script_dir, userfilesdirectory ) # check if there is a replace file - if(directory=="./csvfiles/"): + if(directory=="./csvfiles/" or directory=="./csvfiles/special_lists/"): for filename in os.listdir(userfilesfolder): if(filename == userfilereplacename): # Just override the parameters, and let it run normally @@ -47,7 +47,7 @@ def csv_to_list(csvfilename, antilist=[], directory="./csvfiles/", lowerandstrip csvlist.append(row[0]) # do the add ons! - if(directory=="./csvfiles/"): + if(directory=="./csvfiles/" or directory=="./csvfiles/special_lists/"): if(os.path.isfile(userfilesfolder + csvfilename + "_addon" + ".csv")): with open(userfilesfolder + csvfilename + "_addon" + ".csv", "r", newline="",encoding="utf8") as file: reader = csv.reader(file, delimiter=",") diff --git a/csvfiles/haircolors.csv b/csvfiles/haircolors.csv index 47e268b..ec7f289 100644 --- a/csvfiles/haircolors.csv +++ b/csvfiles/haircolors.csv @@ -15,4 +15,6 @@ White Dark Light -color- --color- and -color- \ No newline at end of file +-color- and -color- +Pink +Rainbow \ No newline at end of file diff --git a/csvfiles/special_lists/animaladditions.csv b/csvfiles/special_lists/animaladditions.csv new file mode 100644 index 0000000..c9ca671 --- /dev/null +++ b/csvfiles/special_lists/animaladditions.csv @@ -0,0 +1,4 @@ +baby +were +giant +monster \ No newline at end of file diff --git a/csvfiles/special_lists/backgroundtypes.csv b/csvfiles/special_lists/backgroundtypes.csv new file mode 100644 index 0000000..6938380 --- /dev/null +++ b/csvfiles/special_lists/backgroundtypes.csv @@ -0,0 +1,14 @@ +background is -location- +background is [-location-|-location-] +background is -building- +background is [-building-|-building-] +background is [-location-|-building-] +inside a -building- +background is -descriptor- -location- +background is -descriptor- -building- +inside a -descriptor- -building- +plain background +plain -color- background +-color- and -color- background +-descriptor- background +-culture- background \ No newline at end of file diff --git a/csvfiles/special_lists/buildaccessorie.csv b/csvfiles/special_lists/buildaccessorie.csv new file mode 100644 index 0000000..86c5dbf --- /dev/null +++ b/csvfiles/special_lists/buildaccessorie.csv @@ -0,0 +1,11 @@ +-accessory- +-descriptor- -accessory- +-culture- -accessory- +-color- -accessory- +-accessory-, -accessory- +-descriptor- -accessory-, -accessory- +-descriptor- -accessory-, -descriptor- -accessory- +-descriptor- -accessory-, -culture- -accessory- +-culture- -accessory-, -accessory- +-accessory-, -accessory-, -accessory- +-descriptor- -accessory-, -accessory-, -accessory- \ No newline at end of file diff --git a/csvfiles/special_lists/buildhair.csv b/csvfiles/special_lists/buildhair.csv new file mode 100644 index 0000000..cf0b0c0 --- /dev/null +++ b/csvfiles/special_lists/buildhair.csv @@ -0,0 +1,6 @@ +-haircolor- hair styled as -hairstyle- +-descriptor- hair styled as -hairstyle- +-hairstyle- hair +-descriptor- hair +-descriptor- -haircolor- hair +-culture- hair \ No newline at end of file diff --git a/csvfiles/special_lists/buildoutfit.csv b/csvfiles/special_lists/buildoutfit.csv new file mode 100644 index 0000000..3575c71 --- /dev/null +++ b/csvfiles/special_lists/buildoutfit.csv @@ -0,0 +1,13 @@ +-descriptor- -outfit- +-descriptor- -culture- -outfit- +-descriptor- -culture- -material- -outfit- +-descriptor- -culture- -material- -color- -outfit- +-culture- -outfit- +-material- -outfit- +-color- -outfit- +-material- -color- -outfit- +-descriptor- -color- -outfit- +-descriptor- -material- -outfit- +-job- -outfit- +[-outfit-|-outfit-] +-descriptor- [-outfit-|-outfit-] \ No newline at end of file diff --git a/csvfiles/special_lists/humanadditions.csv b/csvfiles/special_lists/humanadditions.csv new file mode 100644 index 0000000..2cce8bc --- /dev/null +++ b/csvfiles/special_lists/humanadditions.csv @@ -0,0 +1,13 @@ +riding a -animal- +holding a -object- +driving a -vehicle- +visiting a -building- +visiting -location- +with a -animal- +surrounded by -object-s +eating -food- +and -fictional- +and -nonfictional- +cosplaying as -fictional- +with -color- skin +with -material- skin \ No newline at end of file diff --git a/csvfiles/special_lists/insideshots.csv b/csvfiles/special_lists/insideshots.csv new file mode 100644 index 0000000..654e20d --- /dev/null +++ b/csvfiles/special_lists/insideshots.csv @@ -0,0 +1,4 @@ +from inside of a -location- +from inside of a -building- +from inside of a -descriptor- -location- +from inside of a -descriptor- -building- \ No newline at end of file diff --git a/csvfiles/special_lists/objectadditions.csv b/csvfiles/special_lists/objectadditions.csv new file mode 100644 index 0000000..5100cc3 --- /dev/null +++ b/csvfiles/special_lists/objectadditions.csv @@ -0,0 +1,11 @@ +with a face +made from -material- +detailed with -material- patterns +detailed with -material- -descriptor- patterns +-descriptor- details +-color- patterns +-material- patterns +-descriptor- -color- patterns +-material- frame +intricate details +smooth \ No newline at end of file diff --git a/csvfiles/special_lists/photoadditions.csv b/csvfiles/special_lists/photoadditions.csv new file mode 100644 index 0000000..9e21197 --- /dev/null +++ b/csvfiles/special_lists/photoadditions.csv @@ -0,0 +1 @@ +film grain \ No newline at end of file diff --git a/main.py b/main.py index 763b142..ef016f4 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s originalsize=size originalmodel = model originalimg2imgmodel = img2imgmodel + insanitylevel = int(insanitylevel) if(onlyupscale==True): script_dir = os.path.dirname(os.path.abspath(__file__)) # Script directory diff --git a/prompttester.py b/prompttester.py new file mode 100644 index 0000000..bd5f12c --- /dev/null +++ b/prompttester.py @@ -0,0 +1,38 @@ +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 generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", imagetype="all",silentmode=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma",givensubject="",smartsubject=True,giventypeofimage=""): + loops = int(amount) # amount of images to generate + steps = 0 + + insanitylevel = int(insanitylevel) + while steps < loops: + # build prompt + if(silentmode==True and workprompt == ""): + print("Trying to use provided workflow prompt, but is empty. Generating a random prompt instead.") + + result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, False,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage) + + print("") + print("loop " + str(steps)) + print("") + + + + + steps += 1 + + + print("") + print("All done!") + +generateprompts(100,10) \ No newline at end of file diff --git a/scripts/onebuttonprompt.py b/scripts/onebuttonprompt.py index a31390f..d40ab27 100644 --- a/scripts/onebuttonprompt.py +++ b/scripts/onebuttonprompt.py @@ -730,4 +730,4 @@ class Script(scripts.Script): # just return all the things p.n_iter = 0 p.batch_size = 0 - return Processed(p=p, images_list=images, info=infotexts[0], infotexts=infotexts, all_seeds=all_seeds, all_prompts=all_prompts) + return Processed(p=p, images_list=images, info=infotexts[0], infotexts=infotexts, all_seeds=all_seeds, all_prompts=all_prompts) \ No newline at end of file