Skip to content

Commit 571fcfa

Browse files
committed
Convert CheckpointSelector to CheckpointLoaderWithName
Fixes 2 issues: - oversized search fields (giriss#5) - selector breaking when model files are added/removed at runtime
1 parent 8c4ba25 commit 571fcfa

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

nodes.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,29 @@ def INPUT_TYPES(cls):
166166
def get_float(self, float):
167167
return (float,)
168168

169+
class CheckpointLoaderWithName:
170+
RETURN_TYPES = ("MODEL", "CLIP", "VAE", "STRING",)
171+
RETURN_NAMES = ("MODEL", "CLIP", "VAE", "modelname")
172+
FUNCTION = "load_checkpoint"
169173

170-
class CheckpointSelector:
171-
CATEGORY = 'ImageSaver/utils'
172-
RETURN_TYPES = (folder_paths.get_filename_list("checkpoints"),)
173-
RETURN_NAMES = ("ckpt_name",)
174-
FUNCTION = "get_names"
174+
CATEGORY = "ImageSaver/utils"
175175

176176
@classmethod
177177
def INPUT_TYPES(cls):
178178
return {"required": {"ckpt_name": (folder_paths.get_filename_list("checkpoints"), ),}}
179179

180-
def get_names(self, ckpt_name):
181-
return (ckpt_name,)
180+
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
181+
ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name)
182+
ckpt_filename = self.get_ckpt_name_string(ckpt_name)
183+
out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
184+
185+
# add checkpoint filename to the output tuple (without the ClipVisionModel)
186+
out = (*out[:3], ckpt_filename)
187+
return out
188+
189+
def get_ckpt_name_string(self, ckpt_name):
190+
filename = os.path.basename(ckpt_name)
191+
return filename
182192

183193

184194
class SamplerSelector:
@@ -258,7 +268,7 @@ def INPUT_TYPES(cls):
258268
"extension": (['png', 'jpeg', 'webp'],),
259269
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
260270
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
261-
"modelname": (folder_paths.get_filename_list("checkpoints"),),
271+
"modelname": ("STRING", {"default": '', "multiline": False}),
262272
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
263273
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
264274
},
@@ -400,7 +410,7 @@ def save_images(self, images, output_path, filename_prefix, comment, extension,
400410

401411

402412
NODE_CLASS_MAPPINGS = {
403-
"Checkpoint Selector (Image Saver)": CheckpointSelector,
413+
"Checkpoint Loader with Name (Image Saver)": CheckpointLoaderWithName,
404414
"Image Saver": ImageSaver,
405415
"Sampler Selector (Image Saver)": SamplerSelector,
406416
"Scheduler Selector (Image Saver)": SchedulerSelector,

0 commit comments

Comments
 (0)