diff --git a/CheckpointLoaderSimpleText.py b/CheckpointLoaderSimpleText.py index 9621667..74c8e4a 100644 --- a/CheckpointLoaderSimpleText.py +++ b/CheckpointLoaderSimpleText.py @@ -5,10 +5,10 @@ from folder_paths import * import random import os if __name__ == os.path.splitext(os.path.basename(__file__))[0] : - from ConsoleColor import print, console + from ConsoleColor import print, console, ccolor from mypath import * else: - from .ConsoleColor import print, console + from .ConsoleColor import print, console, ccolor from .mypath import * #print(__file__) @@ -35,27 +35,13 @@ class CheckpointLoaderSimpleText: CATEGORY = "loaders" def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True): - #ckpt_path =check_name_ckpt(name_split_choice(ckpt_name)) - print(f"ckpt_name",ckpt_name) - ns=name_split_choice(ckpt_name) - print(f"ns",ns) - ckpt_path =get_full_path("checkpoints",ns) - print(f"ckpt_path",ckpt_path) - if ckpt_path is None: - print(f"{ckpt_name} is none") - if ckpt_name.endswith(".safetensors") or ckpt_name.endswith(".ckpt"): - (name,fullpath)=filenameget(os.path.join(models_dir, "checkpoints")+"/**/"+ckpt_name) - else: - (name,fullpath)=filenameget(os.path.join(models_dir, "checkpoints")+"/**/"+ckpt_name+"*.safetensors") - if fullpath is None: - print(f"{ckpt_name} is none") - return - ckpt_path=fullpath + print(f"[{ccolor}]ckpt_name : [/{ccolor}]", ckpt_name) + ckpt_path=getFullPath(ckpt_name,"checkpoints") try: out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) return out except Exception as e: - print("CheckpointLoaderSimpleText Exception : "+ e) + console.print_exception() return diff --git a/LoraLoaderText.py b/LoraLoaderText.py index a10eb16..17e614e 100644 --- a/LoraLoaderText.py +++ b/LoraLoaderText.py @@ -4,9 +4,11 @@ from nodes import * import folder_paths if __name__ == os.path.splitext(os.path.basename(__file__))[0] : - from ConsoleColor import print, console + from ConsoleColor import print, console, ccolor + from mypath import * else: - from .ConsoleColor import print, console + from .ConsoleColor import print, console, ccolor + from .mypath import * class LoraLoaderText: @classmethod @@ -31,26 +33,15 @@ class LoraLoaderText: def load_lora(self, model, clip, lora_name, strength_model, strength_clip): - if lora_name is None or lora_name =="": + print(f"[{ccolor}]lora_name : [/{ccolor}]", lora_name) + if lora_name is None or lora_name =="" : print("[red]No lora_name[/red] : ", lora_name) - return (strength_model, strength_clip) - - if lora_name.endswith('.safetensors') or lora_name.endswith('.ckpt') : - lora_path = folder_paths.get_full_path("loras", lora_name) + return (model, clip) - else: - lora_path = folder_paths.get_full_path("loras", lora_name+'.safetensors') - if lora_path is None: - lora_path = folder_paths.get_full_path("loras", lora_name+'.ckpt') - if lora_path is None: - print("[red]No lora_name[/red] : ", lora_name) - return (model, clip) - #else: - #print("[green]lora_path : [/green]"+ lora_path) - #else: - #print("[green]lora_path : [/green]"+ lora_path) - print("[green]lora_path : [/green]"+ lora_path) - + lora_path=getFullPath(lora_name,"lora") + if lora_path is None: + print("[red]No lora_path of lora_name [/red] : ", lora_name) + return (model, clip) try: model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip) return (model_lora, clip_lora) diff --git a/VAELoaderText.py b/VAELoaderText.py index a23a229..d695378 100644 --- a/VAELoaderText.py +++ b/VAELoaderText.py @@ -3,10 +3,10 @@ import comfy.sd import os from folder_paths import * if __name__ == os.path.splitext(os.path.basename(__file__))[0] : - from ConsoleColor import print, console + from ConsoleColor import print, console, ccolor from mypath import * else: - from .ConsoleColor import print, console + from .ConsoleColor import print, console, ccolor from .mypath import * class VAELoaderText: @@ -25,21 +25,11 @@ class VAELoaderText: #TODO: scale factor? def load_vae(self, vae_name): - if os.path.isabs(vae_name): - vae_path=vae_name - else: - if vae_name.endswith('.safetensors') or vae_name.endswith('.pt') : - vae_path = folder_paths.get_full_path("vae", vae_name) - if vae_path is None: - print(f"{vae_name} is none") - if vae_name.endswith(".safetensors") or vae_name.endswith(".pt"): - (name,fullpath)=filenameget(os.path.join(models_dir, "vae")+"/**/"+vae_name) - else: - (name,fullpath)=filenameget(os.path.join(models_dir, "vae")+"/**/"+vae_name+"*.safetensors") - if fullpath is None: - print(f"{vae_name} is none") - return - vae_path=fullpath - - vae = comfy.sd.VAE(ckpt_path=vae_path) - return (vae,) \ No newline at end of file + print(f"[{ccolor}]vae_name : [/{ccolor}]", vae_name) + vae_path=getFullPath(vae_name,"vae") + try: + vae = comfy.sd.VAE(ckpt_path=vae_path) + return (vae,) + except Exception as e: + console.print_exception() + return \ No newline at end of file diff --git a/mypath.py b/mypath.py index f53b5ab..ed7b0b5 100644 --- a/mypath.py +++ b/mypath.py @@ -3,6 +3,7 @@ import json import ast import os, glob import random +from folder_paths import * if __name__ == os.path.splitext(os.path.basename(__file__))[0] : from ConsoleColor import print, console else: @@ -79,3 +80,33 @@ def filenameget(v_path): name=os.path.basename(fullpath) #r_path=[os.path.basename(fullpath) for fullpath in fullpaths] return (name,fullpath) + +# "test","vae",["pt","safetensors"] +def getFullPath(p,k,el=["safetensors","ckpt","pt"]): + if os.path.isabs(p): + path=p + else: + path=os.path.join(models_dir,k+"/**/",p) + #print(f"path : ", path) + t=False + for e in el: + if p.endswith('.'+e): + t=True + break + if t: + files=glob.glob(path, recursive=True) + else: + for e in el: + t=path+"."+e + #print(f"t : ", t) + files=glob.glob(t, recursive=True) + if len(files): + break + result=None + #print(f"files : ", files) + if len(files): + result=random.choice(files) + print(f"result : ", result) + else: + print("[red]No file in path[/red] : ", path) + return result \ No newline at end of file