Browse Source

Fix ControlNet not applying to refiner

pull/333/head
Ionite 12 months ago
parent
commit
39c22a2424
No known key found for this signature in database
  1. 4
      StabilityMatrix.Avalonia/Models/Inference/ModuleApplyStepEventArgs.cs
  2. 42
      StabilityMatrix.Avalonia/ViewModels/Inference/Modules/ControlNetModule.cs
  3. 12
      StabilityMatrix.Avalonia/ViewModels/Inference/SamplerCardViewModel.cs

4
StabilityMatrix.Avalonia/Models/Inference/ModuleApplyStepEventArgs.cs

@ -40,7 +40,7 @@ public class ModuleApplyStepEventArgs : EventArgs
public (
ConditioningNodeConnection Positive,
ConditioningNodeConnection Negative
) Conditioning { get; set; }
)? Conditioning { get; set; }
/// <summary>
/// Temporary refiner conditioning apply step, used by samplers to apply control net.
@ -48,7 +48,7 @@ public class ModuleApplyStepEventArgs : EventArgs
public (
ConditioningNodeConnection Positive,
ConditioningNodeConnection Negative
) RefinerConditioning { get; set; }
)? RefinerConditioning { get; set; }
/// <summary>
/// Temporary model apply step, used by samplers to apply control net.

42
StabilityMatrix.Avalonia/ViewModels/Inference/Modules/ControlNetModule.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using StabilityMatrix.Avalonia.Controls;
@ -23,7 +24,7 @@ public class ControlNetModule : ModuleBase
AddCards(vmFactory.Get<ControlNetCardViewModel>());
}
public IEnumerable<ImageSource> GetInputImages()
protected override IEnumerable<ImageSource> GetInputImages()
{
if (GetCard<ControlNetCardViewModel>().SelectImageCardViewModel.ImageSource is { } image)
{
@ -43,7 +44,7 @@ public class ControlNetModule : ModuleBase
Image =
card.SelectImageCardViewModel.ImageSource?.GetHashGuidFileNameCached(
"Inference"
) ?? throw new ValidationException()
) ?? throw new ValidationException("No ImageSource")
}
);
@ -51,18 +52,22 @@ public class ControlNetModule : ModuleBase
new ComfyNodeBuilder.ControlNetLoader
{
Name = e.Nodes.GetUniqueName("ControlNetLoader"),
ControlNetName = card.SelectedModel?.FileName ?? throw new ValidationException(),
ControlNetName =
card.SelectedModel?.FileName
?? throw new ValidationException("No SelectedModel"),
}
);
var controlNetApply = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.ControlNetApplyAdvanced
{
Name = e.Nodes.GetUniqueName("ControlNet"),
Name = e.Nodes.GetUniqueName("ControlNetApply"),
Image = imageLoad.Output1,
ControlNet = controlNetLoader.Output,
Positive = e.Temp.Conditioning.Positive,
Negative = e.Temp.Conditioning.Negative,
Positive =
e.Temp.Conditioning?.Positive ?? throw new ArgumentException("No Conditioning"),
Negative =
e.Temp.Conditioning?.Negative ?? throw new ArgumentException("No Conditioning"),
Strength = card.Strength,
StartPercent = card.StartPercent,
EndPercent = card.EndPercent,
@ -70,5 +75,28 @@ public class ControlNetModule : ModuleBase
);
e.Temp.Conditioning = (controlNetApply.Output1, controlNetApply.Output2);
// Refiner if available
if (e.Temp.RefinerConditioning is not null)
{
var controlNetRefinerApply = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.ControlNetApplyAdvanced
{
Name = e.Nodes.GetUniqueName("Refiner_ControlNetApply"),
Image = imageLoad.Output1,
ControlNet = controlNetLoader.Output,
Positive = e.Temp.RefinerConditioning.Value.Positive,
Negative = e.Temp.RefinerConditioning.Value.Negative,
Strength = card.Strength,
StartPercent = card.StartPercent,
EndPercent = card.EndPercent,
}
);
e.Temp.RefinerConditioning = (
controlNetRefinerApply.Output1,
controlNetRefinerApply.Output2
);
}
}
}

12
StabilityMatrix.Avalonia/ViewModels/Inference/SamplerCardViewModel.cs

@ -167,8 +167,8 @@ public partial class SamplerCardViewModel
Scheduler = e.Builder.Connections.PrimaryScheduler?.Name!,
Steps = Steps,
Cfg = CfgScale,
Positive = e.Temp.Conditioning.Positive,
Negative = e.Temp.Conditioning.Negative,
Positive = e.Temp.Conditioning?.Positive!,
Negative = e.Temp.Conditioning?.Negative!,
LatentImage = primaryLatent,
Denoise = DenoiseStrength,
}
@ -192,8 +192,8 @@ public partial class SamplerCardViewModel
Cfg = CfgScale,
SamplerName = e.Builder.Connections.PrimarySampler?.Name!,
Scheduler = e.Builder.Connections.PrimaryScheduler?.Name!,
Positive = e.Temp.Conditioning.Positive,
Negative = e.Temp.Conditioning.Negative,
Positive = e.Temp.Conditioning?.Positive!,
Negative = e.Temp.Conditioning?.Negative!,
LatentImage = primaryLatent,
StartAtStep = 0,
EndAtStep = Steps,
@ -215,8 +215,8 @@ public partial class SamplerCardViewModel
Cfg = CfgScale,
SamplerName = e.Builder.Connections.PrimarySampler?.Name!,
Scheduler = e.Builder.Connections.PrimaryScheduler?.Name!,
Positive = e.Temp.RefinerConditioning.Positive,
Negative = e.Temp.RefinerConditioning.Negative,
Positive = e.Temp.RefinerConditioning?.Positive!,
Negative = e.Temp.RefinerConditioning?.Negative!,
// Connect to previous sampler
LatentImage = sampler.Output,
StartAtStep = Steps,

Loading…
Cancel
Save