|
|
@ -2,6 +2,7 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.Models.Inference; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Inference; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Inference; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.Nodes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.Nodes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; |
|
|
@ -58,7 +59,7 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
Action<ComfyNodeBuilder>? postModelLoad = null |
|
|
|
Action<ComfyNodeBuilder>? postModelLoad = null |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Load base checkpoint |
|
|
|
/*// Load base checkpoint |
|
|
|
var checkpointLoader = builder.Nodes.AddNamedNode( |
|
|
|
var checkpointLoader = builder.Nodes.AddNamedNode( |
|
|
|
ComfyNodeBuilder.CheckpointLoaderSimple( |
|
|
|
ComfyNodeBuilder.CheckpointLoaderSimple( |
|
|
|
"CheckpointLoader", |
|
|
|
"CheckpointLoader", |
|
|
@ -73,7 +74,7 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
builder.Connections.PrimaryVAE = builder.Connections.BaseVAE; |
|
|
|
builder.Connections.PrimaryVAE = builder.Connections.BaseVAE; |
|
|
|
|
|
|
|
|
|
|
|
// Run post model load action |
|
|
|
// Run post model load action |
|
|
|
postModelLoad?.Invoke(builder); |
|
|
|
postModelLoad?.Invoke(builder);*/ |
|
|
|
|
|
|
|
|
|
|
|
// Load prompts |
|
|
|
// Load prompts |
|
|
|
var prompt = promptCardViewModel.GetPrompt(); |
|
|
|
var prompt = promptCardViewModel.GetPrompt(); |
|
|
@ -115,6 +116,28 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
builder.Connections.BaseConditioning = positiveClip.Output; |
|
|
|
builder.Connections.BaseConditioning = positiveClip.Output; |
|
|
|
builder.Connections.BaseNegativeConditioning = negativeClip.Output; |
|
|
|
builder.Connections.BaseNegativeConditioning = negativeClip.Output; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply sampler addons (FreeU / ControlNet) to model and conditioning |
|
|
|
|
|
|
|
var samplerStepArgs = new ModuleApplyStepEventArgs |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Builder = builder, |
|
|
|
|
|
|
|
Temp = |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Model = builder.Connections.BaseModel, |
|
|
|
|
|
|
|
Conditioning = (positiveClip.Output, negativeClip.Output) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
samplerCardViewModel.ApplyStep(samplerStepArgs); |
|
|
|
|
|
|
|
var model = samplerStepArgs.Temp.Model; |
|
|
|
|
|
|
|
var conditioning = samplerStepArgs.Temp.Conditioning; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Primary latent encoding vae |
|
|
|
|
|
|
|
var vae = |
|
|
|
|
|
|
|
builder.Connections.PrimaryVAE |
|
|
|
|
|
|
|
?? builder.Connections.BaseVAE |
|
|
|
|
|
|
|
?? throw new ValidationException("No Primary or Base VAE"); |
|
|
|
|
|
|
|
var latent = builder.GetPrimaryAsLatent(vae); |
|
|
|
|
|
|
|
|
|
|
|
// Add base sampler (without refiner) |
|
|
|
// Add base sampler (without refiner) |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
modelCardViewModel |
|
|
|
modelCardViewModel |
|
|
@ -124,18 +147,17 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
var sampler = builder.Nodes.AddNamedNode( |
|
|
|
var sampler = builder.Nodes.AddNamedNode( |
|
|
|
ComfyNodeBuilder.KSampler( |
|
|
|
ComfyNodeBuilder.KSampler( |
|
|
|
"Sampler", |
|
|
|
"Sampler", |
|
|
|
builder.Connections.BaseModel, |
|
|
|
model, |
|
|
|
builder.Connections.Seed, |
|
|
|
builder.Connections.Seed, |
|
|
|
samplerCardViewModel.Steps, |
|
|
|
samplerCardViewModel.Steps, |
|
|
|
samplerCardViewModel.CfgScale, |
|
|
|
samplerCardViewModel.CfgScale, |
|
|
|
samplerCardViewModel.SelectedSampler |
|
|
|
samplerCardViewModel.SelectedSampler |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
samplerCardViewModel.SelectedScheduler |
|
|
|
samplerCardViewModel.SelectedScheduler |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
?? throw new ValidationException("Scheduler not selected"), |
|
|
|
positiveClip.Output, |
|
|
|
conditioning.Positive, |
|
|
|
negativeClip.Output, |
|
|
|
conditioning.Negative, |
|
|
|
builder.GetPrimaryAsLatent() |
|
|
|
latent, |
|
|
|
?? throw new ValidationException("Latent source not set"), |
|
|
|
|
|
|
|
samplerCardViewModel.DenoiseStrength |
|
|
|
samplerCardViewModel.DenoiseStrength |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
@ -150,7 +172,7 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
var sampler = builder.Nodes.AddNamedNode( |
|
|
|
var sampler = builder.Nodes.AddNamedNode( |
|
|
|
ComfyNodeBuilder.KSamplerAdvanced( |
|
|
|
ComfyNodeBuilder.KSamplerAdvanced( |
|
|
|
"Sampler", |
|
|
|
"Sampler", |
|
|
|
builder.Connections.BaseModel, |
|
|
|
model, |
|
|
|
true, |
|
|
|
true, |
|
|
|
builder.Connections.Seed, |
|
|
|
builder.Connections.Seed, |
|
|
|
totalSteps, |
|
|
|
totalSteps, |
|
|
@ -159,9 +181,9 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
samplerCardViewModel.SelectedScheduler |
|
|
|
samplerCardViewModel.SelectedScheduler |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
?? throw new ValidationException("Sampler not selected"), |
|
|
|
positiveClip.Output, |
|
|
|
conditioning.Positive, |
|
|
|
negativeClip.Output, |
|
|
|
conditioning.Negative, |
|
|
|
builder.GetPrimaryAsLatent(), |
|
|
|
latent, |
|
|
|
0, |
|
|
|
0, |
|
|
|
samplerCardViewModel.Steps, |
|
|
|
samplerCardViewModel.Steps, |
|
|
|
true |
|
|
|
true |
|
|
@ -180,7 +202,7 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
Action<ComfyNodeBuilder>? postModelLoad = null |
|
|
|
Action<ComfyNodeBuilder>? postModelLoad = null |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Load refiner checkpoint |
|
|
|
/*// Load refiner checkpoint |
|
|
|
var checkpointLoader = builder.Nodes.AddNamedNode( |
|
|
|
var checkpointLoader = builder.Nodes.AddNamedNode( |
|
|
|
ComfyNodeBuilder.CheckpointLoaderSimple( |
|
|
|
ComfyNodeBuilder.CheckpointLoaderSimple( |
|
|
|
"Refiner_CheckpointLoader", |
|
|
|
"Refiner_CheckpointLoader", |
|
|
@ -195,7 +217,7 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
builder.Connections.PrimaryVAE = builder.Connections.RefinerVAE; |
|
|
|
builder.Connections.PrimaryVAE = builder.Connections.RefinerVAE; |
|
|
|
|
|
|
|
|
|
|
|
// Run post model load action |
|
|
|
// Run post model load action |
|
|
|
postModelLoad?.Invoke(builder); |
|
|
|
postModelLoad?.Invoke(builder);*/ |
|
|
|
|
|
|
|
|
|
|
|
// Load prompts |
|
|
|
// Load prompts |
|
|
|
var prompt = promptCardViewModel.GetPrompt(); |
|
|
|
var prompt = promptCardViewModel.GetPrompt(); |
|
|
@ -272,7 +294,11 @@ public static class ComfyNodeBuilderExtensions |
|
|
|
new ComfyNodeBuilder.PreviewImage |
|
|
|
new ComfyNodeBuilder.PreviewImage |
|
|
|
{ |
|
|
|
{ |
|
|
|
Name = "SaveImage", |
|
|
|
Name = "SaveImage", |
|
|
|
Images = builder.GetPrimaryAsImage() |
|
|
|
Images = builder.GetPrimaryAsImage( |
|
|
|
|
|
|
|
builder.Connections.PrimaryVAE |
|
|
|
|
|
|
|
?? builder.Connections.RefinerVAE |
|
|
|
|
|
|
|
?? builder.Connections.BaseVAE |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|