diff --git a/CheckpointLoaderSimpleText.py b/CheckpointLoaderSimpleText.py index b5210f5..942919c 100644 --- a/CheckpointLoaderSimpleText.py +++ b/CheckpointLoaderSimpleText.py @@ -1,8 +1,8 @@ import os import comfy.sd from nodes import * -import folder_paths -import random +from folder_paths import * +import random import os if __name__ == os.path.splitext(os.path.basename(__file__))[0] : from ConsoleColor import print, console @@ -35,10 +35,19 @@ 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)) + #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") - return + (name,fullpath)=filenameget(os.path.join(models_dir, "checkpoints")+"/**/"+ckpt_name+"*.safetensors") + if fullpath is None: + print(f"{name} is none") + return + ckpt_path=fullpath 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 diff --git a/mypath.py b/mypath.py index 6f8d19c..11803c0 100644 --- a/mypath.py +++ b/mypath.py @@ -1,9 +1,7 @@ import sys import json import ast -import os -from folder_paths import supported_ckpt_extensions,supported_pt_extensions -import folder_paths +import os, glob import random if __name__ == os.path.splitext(os.path.basename(__file__))[0] : from ConsoleColor import print, console @@ -49,8 +47,6 @@ print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style= mainfolder = os.path.dirname(mainFile) print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN") - - def check_name(kind,name,supported_extensions): for ext in supported_extensions: if name.lower().endswith(ext): @@ -70,4 +66,16 @@ def check_name_pt(kind,name): return check_name(kind,name,supported_pt_extensions) def name_split_choice(name): - return random.choice(name.split('|')) \ No newline at end of file + return random.choice(name.split('|')) + +#---------------------- + +def filenameget(v_path): + t_path=os.path.join(os.path.dirname(__file__),v_path) + print(t_path) + fullpaths=glob.glob(t_path) + print(fullpaths) + fullpath=random.choice(fullpaths) + name=os.path.basename(fullpath) + #r_path=[os.path.basename(fullpath) for fullpath in fullpaths] + return (name,fullpath)