Merge pull request #83 from AIrjen/csv_to_control_generation

Csv to control generation
This commit is contained in:
AIrjen
2023-07-09 09:23:15 +02:00
committed by GitHub
31 changed files with 4497 additions and 1850 deletions
+265 -14
View File
@@ -13,14 +13,21 @@ from modules.shared import opts, cmd_opts, state
from build_dynamic_prompt import *
from main import *
from model_lists import *
from csv_reader import *
subjects = ["all","object","animal","humanoid", "landscape", "concept"]
#subjects = ["all","object","animal","humanoid", "landscape", "concept"]
subjects =["all"]
subjectsubtypesobject = ["all"]
subjectsubtypeshumanoid = ["all"]
subjectsubtypesconcept = ["all"]
artists = ["all", "none", "popular", "greg mode", "3D", "abstract", "angular", "anime" ,"architecture", "art nouveau", "art deco", "baroque", "bauhaus", "cartoon", "character", "children's illustration", "cityscape", "clean", "cloudscape", "collage", "colorful", "comics", "cubism", "dark", "detailed", "digital", "expressionism", "fantasy", "fashion", "fauvism", "figurativism", "gore", "graffiti", "graphic design", "high contrast", "horror", "impressionism", "installation", "landscape", "light", "line drawing", "low contrast", "luminism", "magical realism", "manga", "melanin", "messy", "monochromatic", "nature", "nudity", "photography", "pop art", "portrait", "primitivism", "psychedelic", "realism", "renaissance", "romanticism", "scene", "sci-fi", "sculpture", "seascape", "space", "stained glass", "still life", "storybook realism", "street art", "streetscape", "surrealism", "symbolism", "textile", "ukiyo-e", "vibrant", "watercolor", "whimsical"]
imagetypes = ["all", "all - force multiple", "photograph", "octane render","digital art","concept art", "painting", "portrait", "anime key visual", "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode"]
promptmode = ["at the back", "in the front"]
promptcompounder = ["1", "2", "3", "4", "5"]
ANDtogglemode = ["none", "automatic", "prefix AND prompt + suffix", "prefix + prefix + prompt + suffix"]
seperatorlist = ["comma", "AND", "BREAK"]
genders = ["all", "male", "female"]
#for autorun and upscale
sizelist = ["all", "portrait", "wide", "square", "ultrawide"]
@@ -64,7 +71,135 @@ for filename in os.listdir(userfilesfolder):
# directly insert into the artists list
artists.insert(2, name)
# on startup, check if we have a config file, or else create it
config = load_config_csv()
# load subjects stuff from config
generatevehicle = True
generateobject = True
generatefood = True
generatebuilding = True
generatespace = True
generateflora = True
generateanimal = True
generatemanwoman = True
generatemanwomanrelation = True
generatefictionalcharacter = True
generatenonfictionalcharacter = True
generatehumanoids = True
generatejob = True
generatefirstnames = True
generatelandscape = True
generateevent = True
generateconcepts = True
generatepoemline = True
generatesongline = True
for item in config:
# objects
if item[0] == 'subject_vehicle' and item[1] != 'on':
generatevehicle = False
if item[0] == 'subject_object' and item[1] != 'on':
generateobject = False
if item[0] == 'subject_food' and item[1] != 'on':
generatefood = False
if item[0] == 'subject_building' and item[1] != 'on':
generatebuilding = False
if item[0] == 'subject_space' and item[1] != 'on':
generatespace = False
if item[0] == 'subject_flora' and item[1] != 'on':
generateflora = False
# animals
if item[0] == 'subject_animal' and item[1] != 'on':
generateanimal = False
# humanoids
if item[0] == 'subject_manwoman' and item[1] != 'on':
generatemanwoman = False
if item[0] == 'subject_manwomanrelation' and item[1] != 'on':
generatemanwomanrelation = False
if item[0] == 'subject_fictional' and item[1] != 'on':
generatefictionalcharacter = False
if item[0] == 'subject_nonfictional' and item[1] != 'on':
generatenonfictionalcharacter = False
if item[0] == 'subject_humanoid' and item[1] != 'on':
generatehumanoids = False
if item[0] == 'subject_job' and item[1] != 'on':
generatejob = False
if item[0] == 'subject_firstnames' and item[1] != 'on':
generatefirstnames = False
# landscape
if item[0] == 'subject_landscape' and item[1] != 'on':
generatelandscape = False
# concept
if item[0] == 'subject_event' and item[1] != 'on':
generateevent = False
if item[0] == 'subject_concept' and item[1] != 'on':
generateconcepts = False
if item[0] == 'poemline' and item[1] != 'on':
generatepoemline = False
if item[0] == 'songline' and item[1] != 'on':
generatesongline = False
# build up all subjects we can choose based on the loaded config file
if(generatevehicle or generateobject or generatefood or generatebuilding or generatespace):
subjects.append("object")
if(generateanimal):
subjects.append("animal")
if(generatemanwoman or generatemanwomanrelation or generatefictionalcharacter or generatenonfictionalcharacter or generatehumanoids or generatejob):
subjects.append("humanoid")
if(generatelandscape):
subjects.append("landscape")
if(generateevent or generateconcepts or generatepoemline or generatesongline):
subjects.append("concept")
# do the same for the subtype subjects
# subjectsubtypesobject = ["all"]
# subjectsubtypeshumanoid = ["all"]
# subjectsubtypesconcept = ["all"]
# objects first
if(generateobject):
subjectsubtypesobject.append("generic objects")
if(generatevehicle):
subjectsubtypesobject.append("vehicles")
if(generatefood):
subjectsubtypesobject.append("food")
if(generatebuilding):
subjectsubtypesobject.append("buildings")
if(generatespace):
subjectsubtypesobject.append("space")
if(generateflora):
subjectsubtypesobject.append("flora")
# humanoids (should I review descriptions??)
if(generatemanwoman):
subjectsubtypeshumanoid.append("generic humans")
if(generatemanwomanrelation):
subjectsubtypeshumanoid.append("generic human relations")
if(generatenonfictionalcharacter):
subjectsubtypeshumanoid.append("celebrities e.a.")
if(generatefictionalcharacter):
subjectsubtypeshumanoid.append("fictional characters")
if(generatehumanoids):
subjectsubtypeshumanoid.append("humanoids")
if(generatejob):
subjectsubtypeshumanoid.append("based on job or title")
if(generatefirstnames):
subjectsubtypeshumanoid.append("based on first name")
# concepts
if(generateevent):
subjectsubtypesconcept.append("event")
if(generateconcepts):
subjectsubtypesconcept.append("the X of Y concepts")
if(generatepoemline):
subjectsubtypesconcept.append("lines from poems")
if(generatesongline):
subjectsubtypesconcept.append("lines from songs")
class Script(scripts.Script):
@@ -76,12 +211,12 @@ class Script(scripts.Script):
def ui(self, is_img2img):
def gen_prompt(insanitylevel, subject, artist, imagetype, antistring, prefixprompt, suffixprompt, promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage, imagemodechance):
def gen_prompt(insanitylevel, subject, artist, imagetype, antistring, prefixprompt, suffixprompt, promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage, imagemodechance,chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept):
promptlist = []
for i in range(5):
promptlist.append(build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring,prefixprompt,suffixprompt,promptcompounderlevel,seperator,givensubject,smartsubject, giventypeofimage, imagemodechance))
promptlist.append(build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring,prefixprompt,suffixprompt,promptcompounderlevel,seperator,givensubject,smartsubject, giventypeofimage, imagemodechance,chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept))
return promptlist
@@ -123,6 +258,15 @@ class Script(scripts.Script):
with gr.Column(scale=1, variant="compact"):
artist = gr.Dropdown(
artists, label="Artists", value="all")
with gr.Row():
chosensubjectsubtypeobject = gr.Dropdown(
subjectsubtypesobject, label="Type of object", value="all", visible=False)
chosensubjectsubtypehumanoid = gr.Dropdown(
subjectsubtypeshumanoid, label="Type of humanoids", value="all", visible=False)
chosensubjectsubtypeconcept = gr.Dropdown(
subjectsubtypesconcept, label="Type of concept", value="all", visible=False)
chosengender = gr.Dropdown(
genders, label="gender", value="all", visible=False)
with gr.Row():
with gr.Column(scale=2, variant="compact"):
imagetype = gr.Dropdown(
@@ -140,8 +284,6 @@ class Script(scripts.Script):
with gr.Row():
givensubject = gr.Textbox(label="Overwrite subject: ", value="")
smartsubject = gr.Checkbox(label="Smart subject", value = True)
with gr.Row():
giventypeofimage = gr.Textbox(label="Overwrite type of image: ", value="")
with gr.Row():
gr.Markdown("""
<font size="2">
@@ -161,6 +303,8 @@ class Script(scripts.Script):
</font>
"""
)
with gr.Row():
giventypeofimage = gr.Textbox(label="Overwrite type of image: ", value="")
with gr.Row():
with gr.Column():
antistring = gr.Textbox(label="Filter out following properties (comma seperated). Example ""film grain, purple, cat"" ")
@@ -195,6 +339,62 @@ class Script(scripts.Script):
5. concept - Can be a concept, such as "a X of Y", or an historical event such as "The Trojan War". It can also generate a line from a poem or a song.
After choosing object, humanoid or concept a subselection menu will show. You can pick further details here. When choosing humanoid, you can also select the gender you wish to generate.
Type of Object:
1. all - selects randomly (default)
2. generic objects - Hodgepodge of objects, can be household items, weapons or any other general object.
3. vehicles - Cars, but also planes, trains and boats.
4. food - Meals, fruits and others.
5. buildings - From churches to libraries to castles.
6. space - Some bigger objects, nebula's, black holes and constellations
7. flora - Flowers and trees.
Type of humanoid:
1. all - selects randomly (default)
2. generic humans - Generic human descriptions. Example values would be Man, Woman, Male, etc
3. generic human relations - Human relations, example values would be Grandpa, Sister, Father, etc
4. celebrities e.a. - Known people, usually celebrities.
5. fictional characters - Movie and videogame characters, such as Mario and Peach.
6. humanoids - Humanoid type races, think Elves, Orcs, Dwarves, etc
7. based on job or title - Examples are Queen, Carpenter, Vampire hunter
8. based on first name - Examples are Anna, James, Emma etc.
gender:
1. all - selects randomly
2. male
3. female
Type of concept:
1. all - selects randomly (default)
2. event - an historical event, or even mythological event. Example The fall of Rome
3. the X of Y concepts - Randomly creates a small sentence, example The Ocean of Thought or The Fortress of Flame, etc
4. lines from poems - Picks a line from a poem
5. lines from songs - Picks a line from a song
</font>
### Artists
@@ -276,7 +476,9 @@ class Script(scripts.Script):
Add a prompt prefix, suffix and the negative prompt in the respective fields. They will be automatically added during processing.
These can be used to add textual inversion and LoRA's. They can also be used to add your models trigger words.
These can be used to add textual inversion and LoRA's to always apply. They can also be used to add your models trigger words.
Please read the custom_files documentation on how to apply random textual inversion and LoRA's.
</font>
@@ -408,11 +610,11 @@ class Script(scripts.Script):
"""
### TXT2IMG
<font size="2">
Start WebUi with option --api for this to work. This is not needed for Vlad.
Start WebUi with option --api for this to work. This is not needed for Vlad SD Next.
Note: This part is entirely optional and you can use the normal generate button.
This part is intended for running an upscaling at the same time.
This part is only intended for running an upscaling at the same time.
</font>
"""
)
@@ -556,7 +758,7 @@ class Script(scripts.Script):
extrasupscaler2codeformerweight = gr.Slider(0, 1, value="0.1", step=0.05, label="CodeFormer weight", visible = False)
genprom.click(gen_prompt, inputs=[insanitylevel,subject, artist, imagetype, antistring,prefixprompt, suffixprompt,promptcompounderlevel, seperator, givensubject,smartsubject,giventypeofimage,imagemodechance], outputs=[prompt1, prompt2, prompt3,prompt4,prompt5])
genprom.click(gen_prompt, inputs=[insanitylevel,subject, artist, imagetype, antistring,prefixprompt, suffixprompt,promptcompounderlevel, seperator, givensubject,smartsubject,giventypeofimage,imagemodechance, chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept], outputs=[prompt1, prompt2, prompt3,prompt4,prompt5])
prompt1toworkflow.click(prompttoworkflowprompt, inputs=prompt1, outputs=workprompt)
prompt2toworkflow.click(prompttoworkflowprompt, inputs=prompt2, outputs=workprompt)
@@ -564,10 +766,59 @@ 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])
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])
automatedoutputsfolderbutton.click(openfolder)
# turn things on and off for gender
def subjectsvalue(subject):
enable=(subject=="humanoid")
return {
chosengender: gr.update(visible=enable),
}
subject.change(
subjectsvalue,
[subject],
[chosengender]
)
# turn things on and off for subject subtype object
def subjectsvalueforsubtypeobject(subject):
enable=(subject=="object")
return {
chosensubjectsubtypeobject: gr.update(visible=enable),
}
subject.change(
subjectsvalueforsubtypeobject,
[subject],
[chosensubjectsubtypeobject]
)
# turn things on and off for subject subtype humanoid
def subjectsvalueforsubtypeobject(subject):
enable=(subject=="humanoid")
return {
chosensubjectsubtypehumanoid: gr.update(visible=enable),
}
subject.change(
subjectsvalueforsubtypeobject,
[subject],
[chosensubjectsubtypehumanoid]
)
# turn things on and off for subject subtype concept
def subjectsvalueforsubtypeconcept(subject):
enable=(subject=="concept")
return {
chosensubjectsubtypeconcept: gr.update(visible=enable),
}
subject.change(
subjectsvalueforsubtypeconcept,
[subject],
[chosensubjectsubtypeconcept]
)
# Turn things off and on for onlyupscale and txt2img
def onlyupscalevalues(onlyupscale):
onlyupscale = not onlyupscale
@@ -670,12 +921,12 @@ class Script(scripts.Script):
return [insanitylevel,subject, artist, imagetype, prefixprompt,suffixprompt,negativeprompt, promptcompounderlevel, ANDtoggle, silentmode, workprompt, antistring, seperator, givensubject, smartsubject, giventypeofimage, imagemodechance]
return [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):
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):
images = []
infotexts = []
@@ -746,7 +997,7 @@ class Script(scripts.Script):
#Here is where we build a "normal" prompt
preppedprompt += build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring, prefixprompt, suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance)
preppedprompt += build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring, prefixprompt, suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance,chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept)
# set the artist mode back when done (for automatic mode)
artist = artistcopy