support wildcard file name
This commit is contained in:
@@ -5,10 +5,10 @@ from folder_paths import *
|
|||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
||||||
from ConsoleColor import print, console
|
from ConsoleColor import print, console, ccolor
|
||||||
from mypath import *
|
from mypath import *
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console, ccolor
|
||||||
from .mypath import *
|
from .mypath import *
|
||||||
|
|
||||||
#print(__file__)
|
#print(__file__)
|
||||||
@@ -35,27 +35,13 @@ class CheckpointLoaderSimpleText:
|
|||||||
CATEGORY = "loaders"
|
CATEGORY = "loaders"
|
||||||
|
|
||||||
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
|
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
|
||||||
#ckpt_path =check_name_ckpt(name_split_choice(ckpt_name))
|
print(f"[{ccolor}]ckpt_name : [/{ccolor}]", ckpt_name)
|
||||||
print(f"ckpt_name",ckpt_name)
|
ckpt_path=getFullPath(ckpt_name,"checkpoints")
|
||||||
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
|
|
||||||
try:
|
try:
|
||||||
out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
|
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
|
return out
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("CheckpointLoaderSimpleText Exception : "+ e)
|
console.print_exception()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-18
@@ -4,9 +4,11 @@ from nodes import *
|
|||||||
import folder_paths
|
import folder_paths
|
||||||
|
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
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:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console, ccolor
|
||||||
|
from .mypath import *
|
||||||
|
|
||||||
class LoraLoaderText:
|
class LoraLoaderText:
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -31,26 +33,15 @@ class LoraLoaderText:
|
|||||||
|
|
||||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip):
|
def load_lora(self, model, clip, lora_name, strength_model, strength_clip):
|
||||||
|
|
||||||
|
print(f"[{ccolor}]lora_name : [/{ccolor}]", lora_name)
|
||||||
if lora_name is None or 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)
|
|
||||||
|
|
||||||
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)
|
print("[red]No lora_name[/red] : ", lora_name)
|
||||||
return (model, clip)
|
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:
|
try:
|
||||||
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip)
|
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip)
|
||||||
return (model_lora, clip_lora)
|
return (model_lora, clip_lora)
|
||||||
|
|||||||
+8
-18
@@ -3,10 +3,10 @@ import comfy.sd
|
|||||||
import os
|
import os
|
||||||
from folder_paths import *
|
from folder_paths import *
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
||||||
from ConsoleColor import print, console
|
from ConsoleColor import print, console, ccolor
|
||||||
from mypath import *
|
from mypath import *
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console, ccolor
|
||||||
from .mypath import *
|
from .mypath import *
|
||||||
|
|
||||||
class VAELoaderText:
|
class VAELoaderText:
|
||||||
@@ -25,21 +25,11 @@ class VAELoaderText:
|
|||||||
|
|
||||||
#TODO: scale factor?
|
#TODO: scale factor?
|
||||||
def load_vae(self, vae_name):
|
def load_vae(self, vae_name):
|
||||||
if os.path.isabs(vae_name):
|
print(f"[{ccolor}]vae_name : [/{ccolor}]", vae_name)
|
||||||
vae_path=vae_name
|
vae_path=getFullPath(vae_name,"vae")
|
||||||
else:
|
try:
|
||||||
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)
|
vae = comfy.sd.VAE(ckpt_path=vae_path)
|
||||||
return (vae,)
|
return (vae,)
|
||||||
|
except Exception as e:
|
||||||
|
console.print_exception()
|
||||||
|
return
|
||||||
@@ -3,6 +3,7 @@ import json
|
|||||||
import ast
|
import ast
|
||||||
import os, glob
|
import os, glob
|
||||||
import random
|
import random
|
||||||
|
from folder_paths import *
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
||||||
from ConsoleColor import print, console
|
from ConsoleColor import print, console
|
||||||
else:
|
else:
|
||||||
@@ -79,3 +80,33 @@ def filenameget(v_path):
|
|||||||
name=os.path.basename(fullpath)
|
name=os.path.basename(fullpath)
|
||||||
#r_path=[os.path.basename(fullpath) for fullpath in fullpaths]
|
#r_path=[os.path.basename(fullpath) for fullpath in fullpaths]
|
||||||
return (name,fullpath)
|
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
|
||||||
Reference in New Issue
Block a user