Archived
69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
"""
|
|
Base workflow class with common functionality.
|
|
All workflows should inherit from this class.
|
|
"""
|
|
from comfy_script.runtime import *
|
|
from comfy_script.runtime.nodes import *
|
|
|
|
class BaseWorkflow:
|
|
"""Base class for ComfyScript workflows with common utilities."""
|
|
|
|
def __init__(self, params):
|
|
self.params = params
|
|
|
|
def load_checkpoints(self):
|
|
"""
|
|
Load and optionally merge checkpoints.
|
|
Automatically merges if multiple checkpoints are provided.
|
|
|
|
Returns:
|
|
tuple: (model, clip, vae)
|
|
"""
|
|
checkpoints = self.params.checkpoints
|
|
|
|
if not checkpoints:
|
|
raise ValueError("At least one checkpoint is required")
|
|
|
|
if len(checkpoints) == 1:
|
|
# Single checkpoint - load directly
|
|
self.model, self.clip, self.vae = CheckpointLoaderSimple(checkpoints[0])
|
|
else:
|
|
# Multiple checkpoints - merge them
|
|
self.model, self.clip, self.vae = self._merge_checkpoints(checkpoints)
|
|
|
|
return self.model, self.clip, self.vae
|
|
|
|
def _merge_checkpoints(self, checkpoints):
|
|
# Load first checkpoint
|
|
model, clip, vae = CheckpointLoaderSimple(checkpoints[0])
|
|
|
|
# Merge with each additional checkpoint
|
|
merge_ratio = 1.0 / len(checkpoints)
|
|
|
|
for i in range(1, len(checkpoints)):
|
|
model_next, clip_next, _ = CheckpointLoaderSimple(checkpoints[i])
|
|
model = ModelMergeSimple(model, model_next, merge_ratio)
|
|
clip = CLIPMergeSimple(clip, clip_next, merge_ratio)
|
|
|
|
return model, clip, vae
|
|
|
|
def apply_loras(self, model=None, clip=None):
|
|
for lora in self.params.loras:
|
|
if not lora.disabled:
|
|
model, clip = LoraLoader(
|
|
model, clip, lora.apiName,
|
|
lora.parameters.strength_model,
|
|
lora.parameters.strength_clip
|
|
)
|
|
|
|
return model, clip
|
|
|
|
def run(self):
|
|
"""
|
|
Main execution method. Override this in subclasses.
|
|
|
|
Returns:
|
|
dict: Result with prompt_id, status, and output data
|
|
"""
|
|
raise NotImplementedError("Subclasses must implement run() method")
|