diff --git a/call_txt2img.py b/call_txt2img.py index d5c5e01..aefbbe9 100644 --- a/call_txt2img.py +++ b/call_txt2img.py @@ -9,7 +9,7 @@ from model_lists import * import time import random -def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "currently selected model",samplingsteps = "40",cfg= "7",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",negativeprompt="",qualityhiresfix = False, qualitymode = "highest", qualitykeep="keep used", basesize="512"): +def call_txt2img(passingprompt,size,upscale,debugmode,filename="",model = "currently selected model",samplingsteps = "40",cfg= "7",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",negativeprompt="",qualityhiresfix = False, qualitymode = "highest", qualitykeep="keep used", basesize="512"): @@ -18,6 +18,7 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr checkprompt = passingprompt.lower() + #set the URL for the API url = apiurl @@ -28,29 +29,15 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr steps="10" cfg_scale = cfg + originalsize = size #size - # from base ratio - if(ratio=='wide' and basesize != "1024"): - width = str(int(basesize) + 256) - height = basesize - elif(ratio=='wide' and basesize == "1024"): - width = "1152" - height = "896" - elif(ratio=='portrait' and basesize != "1024"): - width = basesize - height = str(int(basesize) + 256) - elif(ratio=='portrait' and basesize == "1024"): - width = "896" - height = "1152" - elif(ratio=='ultrawide'): - width = "1280" - height = "360" - elif(ratio=='ultraheight'): - width = "360" - height = "1280" - else: - width = basesize - height = basesize + sizes = setsize(size, basesize,originalsize) + width = sizes[0] + height = sizes[1] + + + + #upscaler enable_hr = upscale if(debugmode==1 or qualityhiresfix == True): @@ -117,6 +104,10 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr imagelist = [] pnginfolist = [] seedlist = [] + widthlist = [] + heightlist = [] + usedwidht = width + usedheight = height usedseed = -1 imagethatiskept = "" @@ -163,6 +154,14 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr # randomize the seed ( A number between 0 and 4,294,967,295 ) seed = random.randrange(1, 4294967295) payload["seed"] = seed + + # do we need to randomize the size? + if(originalsize=='all' or originalsize == 'wild'): + sizes = setsize(size, basesize, originalsize) + width = sizes[0] + height = sizes[1] + payload["width"] = width + payload["height"] = height # If we don't get an image back, we want to retry a few times. Max 3 times for i in range(4): @@ -211,6 +210,8 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr scoredeclist.append(score) score = round(score,1) seedlist.append(seed) + widthlist.append(width) + heightlist.append(height) scorelist.append(score) imagelist.append(outputTXT2IMGFull) @@ -223,7 +224,6 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr else: runstodo = MaxRuns - Runs - 1 print("Not a good result. Retrying for another " + str(runstodo) + " times or until the image is good enough.") - # randomize the seed for the next run except ImportError: @@ -262,6 +262,8 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr outputTXT2IMGFull = imagelist[indexofimagetokeep] #store the image to keep in here, so we can pass it along pnginfo = pnginfolist[indexofimagetokeep] usedseed = seedlist[indexofimagetokeep] + usedwidht = widthlist[indexofimagetokeep] + usedheight = heightlist[indexofimagetokeep] imagethatiskept = imagelist[indexofimagetokeep] imagelist.pop(indexofimagetokeep) @@ -285,6 +287,8 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr print("Going to run the chosen image with hiresfix") payload["seed"] = usedseed + payload["width"] = usedwidht + payload["height"] = usedheight payload["enable_hr"] = "True" # make the filename unique for hiresfix @@ -331,4 +335,38 @@ def call_txt2img(passingprompt,ratio,upscale,debugmode,filename="",model = "curr json_object = json.dumps(payload, indent = 4) txt.write(json_object) - return [outputTXT2IMGFull,pnginfo,continuewithnextpart] \ No newline at end of file + return [outputTXT2IMGFull,pnginfo,continuewithnextpart] + +def setsize(ratio,basesize, originalsize): + + # prompt + size + if(originalsize == "all"): + sizelist = ["portrait", "wide", "square"] + ratio = random.choice(sizelist) + # from base ratio + if(ratio=='wide' and basesize != "1024"): + width = str(int(basesize) + 256) + height = basesize + elif(ratio=='wide' and basesize == "1024"): + width = "1152" + height = "896" + elif(ratio=='portrait' and basesize != "1024"): + width = basesize + height = str(int(basesize) + 256) + elif(ratio=='portrait' and basesize == "1024"): + width = "896" + height = "1152" + elif(ratio=='ultrawide'): + width = "1280" + height = "360" + elif(ratio=='ultraheight'): + width = "360" + height = "1280" + elif(ratio=='wild'): + width = str(round((random.randint(0,4) * 128) + (int(basesize) /2) ) ) # random value of 0 to 512 in steps of 128 + half of base size + height = str(round( (random.randint(0,4) * 128) + (int(basesize) /2) ) ) # random value of 0 to 512 in steps of 128 + half of base size + else: + width = basesize + height = basesize + + return [width, height] \ No newline at end of file diff --git a/csvfiles/accessories.csv b/csvfiles/accessories.csv index bdbf360..e1e2db3 100644 --- a/csvfiles/accessories.csv +++ b/csvfiles/accessories.csv @@ -55,9 +55,9 @@ Cybernetics Mechanical Body Parts Mechanical Arms Mechanical Legs -Robobotic Body Parts -Robobotic Arms -Robobotic Legs +Robotic Body Parts +Robotic Arms +Robotic Legs Headphones Earbuds Cellphone diff --git a/main.py b/main.py index ae76499..c02974d 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s originalpnginfo ="" randomprompt = "" filename="" - originalsize=size + originalmodel = model originalsamplingmethod = samplingmethod @@ -168,11 +168,6 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s filenamecomplete = now.strftime("%Y%m%d%H%M%S") + "_" + filename.replace(" ", "_").strip() - # prompt + size - if(originalsize == "all"): - sizelist = ["portrait", "wide", "square"] - size = random.choice(sizelist) - #Check if there is any random value we have to choose or not if(originalmodel=="all"): @@ -309,3 +304,7 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s print("") print("All done!") + +def tryinterrupt(apiurl="http://127.0.0.1:7860"): + response = requests.post(url=f'{apiurl}/sdapi/v1/interrupt') + \ No newline at end of file diff --git a/scripts/onebuttonprompt.py b/scripts/onebuttonprompt.py index 2118075..3b816ea 100644 --- a/scripts/onebuttonprompt.py +++ b/scripts/onebuttonprompt.py @@ -33,7 +33,7 @@ qualitymodelist = ["highest", "gated"] qualitykeeplist = ["keep used","keep all"] #for autorun and upscale -sizelist = ["all", "portrait", "wide", "square", "ultrawide", "ultraheight"] +sizelist = ["all", "portrait", "wide", "square", "ultrawide", "ultraheight", "wild"] basesizelist = ["512", "768", "1024"] modellist = get_models() @@ -625,6 +625,7 @@ class Script(scripts.Script): with gr.Row(): with gr.Column(scale=1): startmain = gr.Button("Start generating and upscaling!") + interrupt = gr.Button("Interrupt current") automatedoutputsfolderbutton = gr.Button(folder_symbol) apiurl = gr.Textbox(label="URL", value="http://127.0.0.1:7860") with gr.Column(scale=1): @@ -789,6 +790,7 @@ class Script(scripts.Script): 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]) + interrupt.click(tryinterrupt, inputs=[apiurl]) automatedoutputsfolderbutton.click(openfolder)