From a4ed24ff6278b6c522e7a4cc94c68f4ef55c926e Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 11 Aug 2023 17:05:10 +0200 Subject: [PATCH 1/2] Adding auto subject strenght --- build_dynamic_prompt.py | 51 +++++++++++++++++++++++++++++++++++++++-- prompttester.py | 2 +- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 516eb71..f16ae75 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -1236,6 +1236,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += "-culture- " if(mainchooser == "object"): + # first add a wildcard that can be used to create prompt strenght + completeprompt += " -objectstrengthstart-" # if we have an overwrite, then make sure we only take the override if(subtypeobject != "all"): if(subtypeobject == "generic objects"): @@ -1281,8 +1283,12 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += " " + givensubject + " " hybridorswap = "" + # completion of strenght end + completeprompt += "-objectstrengthend-" if(mainchooser == "animal"): + # first add a wildcard that can be used to create prompt strenght + completeprompt += " -objectstrengthstart-" # if we have a given subject, we should skip making an actual subject if(givensubject == ""): @@ -1312,9 +1318,14 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all completeprompt += " " + givensubject + " " hybridorswap = "" + + # completion of strenght end + completeprompt += "-objectstrengthend-" # if we have a given subject, we should skip making an actual subject if(mainchooser == "humanoid"): + # first add a wildcard that can be used to create prompt strenght + completeprompt += " -objectstrengthstart-" if(givensubject==""): if(subjectchooser == "human"): @@ -1387,13 +1398,18 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all else: - completeprompt += " " + givensubject + " " + completeprompt += " " + givensubject + " " + + # completion of strenght end + completeprompt += "-objectstrengthend-" # sometimes add a suffix for more fun! if( (mainchooser == "humanoid" or mainchooser == "animal" or mainchooser == "object") and chance_roll(insanitylevel, subjectconceptsuffixchance)): completeprompt += " of -conceptsuffix- " if(subjectchooser == "landscape"): + # first add a wildcard that can be used to create prompt strenght + completeprompt += " -objectstrengthstart-" # if we have a given subject, we should skip making an actual subject if(givensubject == ""): @@ -1413,6 +1429,9 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all hybridorswap = "" + # completion of strenght end + completeprompt += "-objectstrengthend-" + # shots from inside can create cool effects in landscapes if(chance_roll(insanitylevel, subjectlandscapeaddonlocationchance)): insideshot = 1 @@ -1430,6 +1449,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if(mainchooser == "concept"): + # first add a wildcard that can be used to create prompt strenght + completeprompt += " -objectstrengthstart-" if(givensubject == ""): if(subjectchooser == "event"): completeprompt += " \"" + random.choice(eventlist) + "\" " @@ -1445,7 +1466,10 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all else: completeprompt += " " + givensubject + " " - + # completion of strenght end + completeprompt += "-objectstrengthend-" + + # object additions for i in range(objectadditionsrepeats): @@ -1938,7 +1962,30 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all + # prompt strenght stuff + + # if the given subject already is formed like this ( :1.x) + # then just ignore this + matches = [] + if(givensubject != ""): + pattern = r'\(\w+:\d+\.\d+\)' + matches = re.findall(pattern, givensubject) + + + if(len(completeprompt) > 325 and matches == []): + if(len(completeprompt) < 375): + strenght = "1.1" + elif(len(completeprompt) < 450): + strenght = "1.2" + else: + strenght = "1.3" + completeprompt = completeprompt.replace("-objectstrengthstart-","(") + completeprompt = completeprompt.replace("-objectstrengthend-",":" + strenght + ")") + else: + completeprompt = completeprompt.replace("-objectstrengthstart-","") + completeprompt = completeprompt.replace("-objectstrengthend-","") + # clean it up completeprompt = cleanup(completeprompt, advancedprompting) diff --git a/prompttester.py b/prompttester.py index 4b7cc60..2d3c920 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(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 +generateprompts(10,8,"all","all","all",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","(hello:1.3)",True,"",100, "all", "all", "all", "all", False) \ No newline at end of file From 2b81f0e406604be729c222aef9b6dcc5d659f17e Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 11 Aug 2023 18:50:54 +0200 Subject: [PATCH 2/2] Get samplers dynamically --- main.py | 3 ++- model_lists.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 90a6fbe..ea216cc 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,7 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s originalimg2imgpadding = img2imgpadding + currentlyselectedmodel = "" modellist=get_models() samplerlist=get_samplers() @@ -61,7 +62,7 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s break # Print the 'title' if found - if currentlyselectedmodel is not None: + if currentlyselectedmodel != "": print("current selected model is:") print(currentlyselectedmodel) else: diff --git a/model_lists.py b/model_lists.py index dc4154d..3dece02 100644 --- a/model_lists.py +++ b/model_lists.py @@ -1,6 +1,6 @@ import modules.scripts as scripts import os -from modules import modelloader, paths, shared, sd_models +from modules import modelloader, paths, shared, sd_models, sd_samplers from modules.paths import models_path, script_path import importlib @@ -32,9 +32,16 @@ def get_upscalers(): return upscalerlist def get_samplers(): - #Samplers are hardcoded in WEBui, so lets do it here as well - samplerlist = ["Euler a", "Euler", "LMS","Heun","DPM2","DPM2 a","DPM++ 2S a","DPM++ 2M","DPM++ SDE","DPM fast","DPM adaptive","LMS Karras","DPM2 Karras","DPM2 a Karras","DPM++ 2S a Karras","DPM++ 2M Karras","DPM++ SDE Karras"] - samplerlist += ["DDIM","UniPC", "PLMS"] + + samplerlistfromWebUI = {x.name: x for x in sd_samplers.all_samplers} + samplerlist = list(samplerlistfromWebUI.keys()) + + # fallback method + # Samplers are hardcoded in WEBui, so lets do it here as well + if(samplerlist==[]): + samplerlist = ["Euler a", "Euler", "LMS","Heun","DPM2","DPM2 a","DPM++ 2S a","DPM++ 2M","DPM++ SDE","DPM fast","DPM adaptive","LMS Karras","DPM2 Karras","DPM2 a Karras","DPM++ 2S a Karras","DPM++ 2M Karras","DPM++ SDE Karras"] + samplerlist += ["DDIM","UniPC", "PLMS"] + return samplerlist def get_upscalers_for_img2img():