From 8f82c07a08805d662a62a64fab283f11e43d06c1 Mon Sep 17 00:00:00 2001 From: AIrjen <130234949+AIrjen@users.noreply.github.com> Date: Sat, 20 May 2023 14:05:02 +0200 Subject: [PATCH] Issue 31 windows path (#34) * Redid the way models and upscalers are loaded Add in the fix to actually load the models in One Button Run and Upscale * fixes to make sure models shift correctly --- main.py | 25 +++++++++++++++++++++---- model_lists.py | 51 +++++++------------------------------------------- 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/main.py b/main.py index bd3f7e8..763b142 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,8 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s randomprompt = "" filename="" originalsize=size + originalmodel = model + originalimg2imgmodel = img2imgmodel if(onlyupscale==True): script_dir = os.path.dirname(os.path.abspath(__file__)) # Script directory @@ -104,13 +106,21 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s #Check if there is any random value we have to choose or not - if(model=="all"): + if(originalmodel=="all"): model = random.choice(modellist) #lets not do inpainting models while "inpaint" in model: model = random.choice(modellist) - print("Going to run with model " + model) + print("Going to run with model " + model) + + # set the model here + if(originalmodel!="currently selected model"): + option_payload = { + "sd_model_checkpoint": model + } + response = requests.post(url=f'{apiurl}/sdapi/v1/options', json=option_payload) + if(samplingmethod=="all"): samplingmethod = random.choice(samplerlist) print ("Going to run with sampling method " + samplingmethod) @@ -154,12 +164,19 @@ def generateimages(amount = 1, size = "all",model = "currently selected model",s #Check if there is any random value we have to choose or not - if(img2imgmodel=="all"): + if(originalimg2imgmodel=="all"): img2imgmodel = random.choice(modellist) #lets not do inpainting models while "inpaint" in model: img2imgmodel = random.choice(modellist) - print("Going to upscale with model " + img2imgmodel) + print("Going to upscale with model " + img2imgmodel) + + # set the model here + if(originalimg2imgmodel!="currently selected model"): + option_payload = { + "sd_model_checkpoint": img2imgmodel + } + response = requests.post(url=f'{apiurl}/sdapi/v1/options', json=option_payload) if(img2imgsamplingmethod=="all"): img2imgsamplingmethod = random.choice(img2imgsamplerlist) diff --git a/model_lists.py b/model_lists.py index 56f94e8..006ddff 100644 --- a/model_lists.py +++ b/model_lists.py @@ -1,50 +1,20 @@ import modules.scripts as scripts import os -from modules import modelloader, paths, shared +from modules import modelloader, paths, shared, sd_models from modules.paths import models_path def get_models(): - model_dir = "Stable-diffusion" - model_path = os.path.abspath(os.path.join(paths.models_path, model_dir)) - model_url = None - modellist = modelloader.load_models(model_path=model_path, model_url=model_url, command_path=shared.cmd_opts.ckpt_dir, ext_filter=[".ckpt", ".safetensors"], download_name="v1-5-pruned-emaonly.safetensors", ext_blacklist=[".vae.ckpt", ".vae.safetensors"]) - modellist = [s.replace(model_path, "") for s in modellist] - modellist = [s.replace("\\\\", "") for s in modellist] - modellist = [s.replace("\\", "") for s in modellist] - modellist = [s.replace(".ckpt", "") for s in modellist] - modellist = [s.replace(".safetensors", "") for s in modellist] + modellist = sd_models.checkpoint_tiles() return modellist def get_upscalers(): - #Upscalers are sort of hardcoded as well for Latent, but not for the 2 others. So build it up! + # Upscalers are sort of hardcoded as well for Latent, but not for the 2 others. So build it up! latentlist=["Latent","Latent (antialiased)","Latent (bicubic)","Latent (bicubic antialiased)","Latent (nearest)","Latent (nearest-exact)","Lanczos","Nearest"] - RealESRGAN_dir = "RealESRGAN" - RealESRGAN_path = os.path.abspath(os.path.join(paths.models_path, RealESRGAN_dir)) - model_url = None - RealESRGANlist = modelloader.load_models(model_path=RealESRGAN_path, model_url=model_url, command_path=shared.cmd_opts.ckpt_dir, ext_filter=[".pt", ".pth"], download_name="", ext_blacklist=[".vae.ckpt", ".vae.safetensors"]) - RealESRGANlist = [s.replace(RealESRGAN_path, "") for s in RealESRGANlist] - RealESRGANlist = [s.replace("\\\\", "") for s in RealESRGANlist] - RealESRGANlist = [s.replace("\\", "") for s in RealESRGANlist] - RealESRGANlist = [s.replace(".pth", "") for s in RealESRGANlist] - RealESRGANlist = [s.replace(".pt", "") for s in RealESRGANlist] + upscalerlistfromwWebUI = [x.name for x in shared.sd_upscalers] - ESRGAN_dir = "ESRGAN" - ESRGAN_path = os.path.abspath(os.path.join(paths.models_path, ESRGAN_dir)) - ESRGANlist = modelloader.load_models(model_path=ESRGAN_path, model_url=model_url, command_path=shared.cmd_opts.ckpt_dir, ext_filter=[".pt", ".pth"], download_name="", ext_blacklist=[".vae.ckpt", ".vae.safetensors"]) - ESRGANlist = [s.replace(ESRGAN_path, "") for s in ESRGANlist] - ESRGANlist = [s.replace("\\\\", "") for s in ESRGANlist] - ESRGANlist = [s.replace("\\", "") for s in ESRGANlist] - ESRGANlist = [s.replace(".pth", "") for s in ESRGANlist] - ESRGANlist = [s.replace(".pt", "") for s in ESRGANlist] - - #hardcode some things for Real ESGRAN, because its named differently (note, I could have just hardcoded this. Oh well...) - RealESRGANlist = [s.replace("RealESRGAN_x4plus","R-ESRGAN 4x+") for s in RealESRGANlist] - RealESRGANlist = [s.replace("RealESRGAN x4plus_anime_6B","R-ESRGAN 4x+ Anime6B") for s in RealESRGANlist] - RealESRGANlist = [s.replace("R-ESRGAN 4x+_anime_6B","R-ESRGAN 4x+ Anime6B") for s in RealESRGANlist] - - upscalerlist = latentlist + RealESRGANlist + ESRGANlist + upscalerlist = latentlist + upscalerlistfromwWebUI return upscalerlist def get_samplers(): @@ -54,15 +24,8 @@ def get_samplers(): return samplerlist def get_upscalers_for_img2img(): - upscalerlist = get_upscalers() - # basically have to remove a lot of these, these aren't supported - upscalerlist.remove("Latent") - upscalerlist.remove("Latent (antialiased)") - upscalerlist.remove("Latent (bicubic)") - upscalerlist.remove("Latent (bicubic antialiased)") - upscalerlist.remove("Latent (nearest)") - upscalerlist.remove("Latent (nearest-exact)") - return upscalerlist + upscalerlistfromwWebUI = [x.name for x in shared.sd_upscalers] + return upscalerlistfromwWebUI def get_samplers_for_img2img(): #Samplers are hardcoded in WEBui, so lets do it here as well