Overhaul of model loader. Added lazy switch node to allow for selecting from multiple types dynamically (checkpoint, diffusion, unet)

This commit is contained in:
krator18
2024-12-06 02:06:02 -05:00
parent 4bd17a9375
commit 3fc7c14d5b
3 changed files with 63 additions and 8 deletions
+16 -7
View File
@@ -265,6 +265,7 @@ class Texturaizer_GetJsonData:
return (data_hash,)
checkpoint_names = folder_paths.get_filename_list("checkpoints")
diffusion_names = folder_paths.get_filename_list("diffusion_models")
try:
unet_names = folder_paths.get_filename_list("unet_gguf")
except:
@@ -277,8 +278,8 @@ class Texturaizer_GetModelName(Texturaizer_GetJsonData):
Extends the JSON retrieval functionality to return model-specific information.
"""
RETURN_TYPES = (checkpoint_names, unet_names, "STRING")
RETURN_NAMES = ("checkpoint_name", "unet_name", "data_hash")
RETURN_TYPES = (checkpoint_names, diffusion_names, unet_names, "INT", "STRING")
RETURN_NAMES = ("checkpoint_name", "diffusion_name", "unet_name", "model_type_idx", "data_hash")
OUTPUT_TOOLTIPS = (
"Diffusion checkpoint model name (stable diffusion).",
"Diffusion unet model name (flux).",
@@ -294,9 +295,14 @@ class Texturaizer_GetModelName(Texturaizer_GetJsonData):
"""
data = get_data(directory_optional, data_optional)
scene_data = data.get("scene_info", {})
model = scene_data["ai_model"]
data_hash = calculate_data_hash(model)
return (model, model, data_hash)
checkpoint_model = scene_data.get("checkpoint_model", scene_data.get("ai_model"))
diffusion_model = scene_data.get("diffusion_model", scene_data.get("ai_model"))
unet_model = scene_data.get("unet_model", scene_data.get("ai_model"))
model_type = scene_data.get("model_type", "CHECKPOINT")
model_type_mapping = {"CHECKPOINT": 1, "DIFFUSION": 2, "UNET": 3}
model_type_index = model_type_mapping.get(model_type, 1)
data_hash = calculate_data_hash([checkpoint_model, diffusion_model, unet_model, model_type])
return (checkpoint_model, diffusion_model, unet_model, model_type_index, data_hash)
@staticmethod
def IS_CHANGED(directory_optional="", data_optional={}):
@@ -305,8 +311,11 @@ class Texturaizer_GetModelName(Texturaizer_GetJsonData):
"""
data = get_data(directory_optional, data_optional)
scene_data = data.get("scene_info", {})
model = scene_data["ai_model"]
data_hash = calculate_data_hash(model)
checkpoint_model = scene_data.get("checkpoint_model", scene_data.get("ai_model"))
diffusion_model = scene_data.get("diffusion_model", scene_data.get("ai_model"))
unet_model = scene_data.get("unet_model", scene_data.get("ai_model"))
model_type = scene_data.get("model_type", "CHECKPOINT")
data_hash = calculate_data_hash([checkpoint_model, diffusion_model, unet_model, model_type])
return (data_hash,)
try:
+46
View File
@@ -31,10 +31,56 @@ class Texturaizer_SwitchAny:
return (on_true,) if boolean else (on_false,)
class Texturaizer_SwitchLazy:
"""
Node that switches between three inputs based on an index.
Returns the selected input and blocks others.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"index": ("INT", {"default": 1, "min": 1, "max": 3, "tooltip": "Select which input to output (1-3)."}),
},
"optional": {
"input1": (any, {"lazy": True}),
"input2": (any, {"lazy": True}),
"input3": (any, {"lazy": True}),
}
}
CATEGORY = "Texturaizer"
RETURN_TYPES = (any, 'INT')
RETURN_NAMES = ("selected", 'index')
FUNCTION = "execute"
def check_lazy_status(self, *args, **kwargs):
"""
Determines which input needs to be evaluated based on the index.
"""
selected_index = int(kwargs['index'])
selected_input = f"input{selected_index}"
return [selected_input]
@staticmethod
def execute(*args, **kwargs):
selected_index = int(kwargs['index'])
selected_input = f"input{selected_index}"
if selected_input in kwargs and kwargs[selected_input] is not None:
return kwargs[selected_input], selected_index
else:
print(f"Execution blocked for unselected input: {selected_input}")
return None, selected_index
NODE_CLASS_MAPPINGS = {
"Texturaizer_SwitchAny": Texturaizer_SwitchAny,
"Texturaizer_SwitchLazy": Texturaizer_SwitchLazy,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"Texturaizer_SwitchAny": "Switch Any (Texturaizer)",
"Texturaizer_SwitchLazy": "Switch Lazy (Texturaizer)",
}
+1 -1
View File
@@ -9,7 +9,7 @@ Developed by Luke Kratsios and the LatentSpaceDirective.
More about the creator: www.lukekratsios.com
"""
__version__ = "0.0.1"
__version__ = "0.0.2"
import importlib