using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
[ManagedService]
[Transient]
public class FreeUModule : ModuleBase
{
///
public FreeUModule(ServiceManager vmFactory)
: base(vmFactory)
{
Title = "FreeU";
AddCards(vmFactory.Get());
}
///
/// Applies FreeU to the Model property
///
protected override void OnApplyStep(ModuleApplyStepEventArgs e)
{
var card = GetCard();
// Currently applies to both base and refiner model
// TODO: Add option to apply to either base or refiner
if (e.Builder.Connections.BaseModel is not null)
{
e.Builder.Connections.BaseModel = e.Nodes
.AddTypedNode(
new ComfyNodeBuilder.FreeU
{
Name = e.Nodes.GetUniqueName("FreeU"),
Model = e.Builder.Connections.BaseModel,
B1 = card.B1,
B2 = card.B2,
S1 = card.S1,
S2 = card.S2
}
)
.Output;
}
if (e.Builder.Connections.RefinerModel is not null)
{
e.Builder.Connections.RefinerModel = e.Nodes
.AddTypedNode(
new ComfyNodeBuilder.FreeU
{
Name = e.Nodes.GetUniqueName("Refiner_FreeU"),
Model = e.Builder.Connections.RefinerModel,
B1 = card.B1,
B2 = card.B2,
S1 = card.S1,
S2 = card.S2
}
)
.Output;
}
}
}