filenameget

This commit is contained in:
lilly
2023-03-30 13:57:08 +09:00
parent 98ae062bc0
commit f7d40d0b2d
2 changed files with 27 additions and 10 deletions
+13 -4
View File
@@ -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
+14 -6
View File
@@ -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('|'))
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)