Merge pull request #152 from AIrjen/Prompt_g_and_l

Adding prompt_g and prompt_l into comfyUI
This commit is contained in:
AIrjen
2023-11-23 20:24:19 +01:00
committed by GitHub
4 changed files with 69 additions and 12 deletions
+19 -5
View File
@@ -230,8 +230,8 @@ class OneButtonPrompt:
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("prompt",)
RETURN_TYPES = ("STRING","STRING", "STRING")
RETURN_NAMES = ("prompt","prompt_g", "prompt_l")
FUNCTION = "Comfy_OBP"
@@ -240,9 +240,13 @@ class OneButtonPrompt:
CATEGORY = "OneButtonPrompt"
def Comfy_OBP(self, insanitylevel, custom_subject, seed, artist, imagetype, subject, imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts, emojis, custom_outfit):
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, emojis, seed, custom_outfit)
generatedpromptlist = 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, emojis, seed, custom_outfit, True)
#print(generatedprompt)
return (generatedprompt,)
generatedprompt = generatedpromptlist[0]
prompt_g = generatedpromptlist[1]
prompt_l = generatedpromptlist[2]
return (generatedprompt, prompt_g, prompt_l)
class CreatePromptVariant:
@@ -300,6 +304,10 @@ class SavePromptToFile:
"positive_prompt": ("STRING",{"multiline": True}),
"negative_prompt": ("STRING",{"multiline": True}),
},
"optional": {
"prompt_g": ("STRING",{"multiline": True}),
"prompt_l": ("STRING",{"multiline": True}),
},
}
OUTPUT_NODE = True
@@ -308,7 +316,7 @@ class SavePromptToFile:
CATEGORY = "OneButtonPrompt"
def saveprompttofile(self, positive_prompt, negative_prompt, filename_prefix):
def saveprompttofile(self, positive_prompt, prompt_g, prompt_l, negative_prompt, filename_prefix):
# Some stuff for the prefix
filename_prefix += self.prefix_append
@@ -415,6 +423,12 @@ class SavePromptToFile:
with open(directoryandfilename, 'w', encoding="utf-8") as file:
file.write("prompt: " + positive_prompt + "\n")
if(len(prompt_g) > 0):
file.write("prompt_g: " + prompt_g + "\n")
if(len(prompt_l) > 0):
file.write("prompt_l: " + prompt_l + "\n")
file.write("negative prompt: " + negative_prompt + "\n")
+36 -2
View File
@@ -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", advancedprompting=True, hardturnoffemojis=False, seed=-1, overrideoutfit=""):
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, hardturnoffemojis=False, seed=-1, overrideoutfit="", prompt_g_and_l = False):
# set seed
# For use in ComfyUI (might bring to Automatic1111 as well)
@@ -1535,6 +1535,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
if artistmode in ["enhancing"]:
completeprompt += " ["
# start image type
if(giventypeofimage=="" and generatetype == True):
@@ -1597,6 +1599,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
if(chance_roll(insanitylevel, minivomitprefix2chance) and generateminivomit == True):
completeprompt += " -minivomit-, "
# start shot size
if(mainchooser in ["object", "animal", "humanoid", "concept"] and othertype == 0 and "portrait" not in completeprompt and generateshot == True and chance_roll(insanitylevel,shotsizechance)):
@@ -1610,6 +1614,10 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
genjoboractivity = False
# start subject building
# divider between subject and everything else
completeprompt += " @ "
if(generatesubject == True):
# start with descriptive qualities
@@ -2035,6 +2043,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
if(subjectchooser in ["human", "humanoid", "manwomanrelation","firstname"] and chance_roll(insanitylevel, buildfacechance) and generateface== True):
completeprompt += random.choice(buildfacelist) + ", "
# custom mid list
for i in range(custominputmidrepeats):
if(chance_roll(insanitylevel, custominputmidchance) and generatecustominputmid == True):
@@ -2081,6 +2092,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
if(chance_roll(insanitylevel, generalminilocationchance) and generateminilocationaddition == True):
completeprompt += " -minilocationaddition-, "
# divider between subject and everything else
completeprompt += " @ "
# Add more quality while in greg mode lol
if(originalartistchoice == "greg mode" and generatequality == True):
completeprompt += "-quality-, "
@@ -2875,6 +2891,21 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
# clean it up
completeprompt = cleanup(completeprompt, advancedprompting, insanitylevel)
# Split it up for support for prompt_g (subject) and prompt_l (style)
if("@" in completeprompt and prompt_g_and_l == True):
promptlist = completeprompt.split("@")
prompt_g = cleanup(promptlist[1], advancedprompting, insanitylevel)
prompt_l = cleanup((promptlist[0] + ", " + promptlist[2]).replace("of a",""), advancedprompting, insanitylevel)
elif(prompt_g_and_l == True):
prompt_g = completeprompt
prompt_l = completeprompt
completeprompt = completeprompt.replace(" @ ", " ")
completeprompt = completeprompt.replace("@ ", " ")
completeprompt = completeprompt.replace(" @", " ")
completeprompt = completeprompt.replace("@", " ")
completeprompt = cleanup(completeprompt, advancedprompting, insanitylevel)
#just for me, some fun with posting fake dev messages (ala old sim games)
if(random.randint(1, 50)==1):
print("")
@@ -2882,7 +2913,10 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all
print("")
print(completeprompt)
return completeprompt
if(prompt_g_and_l == False):
return completeprompt
else:
return completeprompt, prompt_g, prompt_l
# function that takes an existing prompt and tries to create a variant out of it
+2 -1
View File
@@ -22,4 +22,5 @@ Rainbow
Ginger
Multicolor
Two-Tone
Trendy
Trendy
Colored
1 Black
22 Ginger
23 Multicolor
24 Two-Tone
25 Trendy
26 Colored
+12 -4
View File
@@ -10,16 +10,23 @@ 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", advancedprompting = True, hardturnoffemojis=False, seed=0, overrideoutfit=""):
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, hardturnoffemojis=False, seed=0, overrideoutfit="", prompt_g_and_l = False):
loops = int(amount) # amount of images to generate
steps = 0
insanitylevel = int(insanitylevel)
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, advancedprompting, hardturnoffemojis, seed, overrideoutfit)
if(prompt_g_and_l == True):
resultlist = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept, advancedprompting, hardturnoffemojis, seed, overrideoutfit, prompt_g_and_l)
result = resultlist[0]
print("prompt_g")
print(resultlist[1])
print("prompt_l")
print(resultlist[2])
else:
result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept, advancedprompting, hardturnoffemojis, seed, overrideoutfit, prompt_g_and_l)
print("")
print("loop " + str(steps))
print("")
@@ -88,7 +95,7 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im
print("")
print("All done!")
generateprompts(100,5
generateprompts(10,5
,"all" # subject
,"all" # artists
,"all" # image type "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode", "fixed styles mode"
@@ -107,4 +114,5 @@ generateprompts(100,5
, True # Turn off emojis
, 0 # seed
, "TESTOUTFIT" #outfit override
, True #prompt_g_and_l
)