Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected async Task<FilePath> WriteOutputImageAsync(
{
GenerationParameters = args.Parameters,
ProjectType = args.Project?.ProjectType,
ProjectName = ProjectFile?.NameWithoutExtension
ProjectName = ProjectFile?.NameWithoutExtension,
};

// Parse to format
Expand Down Expand Up @@ -260,7 +260,7 @@ public async Task RunCustomGeneration(
Project = InferenceProjectDocument.FromLoadable(this),
FilesToTransfer = args.FilesToTransfer,
Parameters = new GenerationParameters(),
ClearOutputImages = true
ClearOutputImages = true,
};

await RunGeneration(generationArgs, cancellationToken);
Expand Down Expand Up @@ -410,7 +410,7 @@ await notificationService.ShowAsync(
{
Title = "Prompt Completed",
Body = $"Prompt [{promptTask.Id[..7].ToLower()}] completed successfully",
BodyImagePath = notificationImage?.FullPath
BodyImagePath = notificationImage?.FullPath,
}
);
}
Expand Down Expand Up @@ -521,14 +521,14 @@ private async Task<List<ImageSource>> ProcessOutputImages(
var opts = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverter() }
Converters = { new JsonStringEnumConverter() },
};
var paramsJson = JsonSerializer.Serialize(parameters, opts);
var smProject = JsonSerializer.Serialize(project, opts);
var metadata = new Dictionary<ExifTag, string>
{
{ ExifTag.ImageDescription, paramsJson },
{ ExifTag.Software, smProject }
{ ExifTag.Software, smProject },
};

var bytesWithMetadata = ImageMetadata.AddMetadataToWebp(imageArray, metadata);
Expand Down Expand Up @@ -779,7 +779,7 @@ out var localSemVersion
{
ShowDialogOnStart = true,
ModificationCompleteTitle = "Extensions Installed",
ModificationCompleteMessage = "Finished installing required extensions"
ModificationCompleteMessage = "Finished installing required extensions",
};
EventManager.Instance.OnPackageInstallProgressAdded(runner);

Expand Down Expand Up @@ -859,8 +859,14 @@ private void AttachRunningNodeChangedHandler(ComfyTask comfyTask)
/// </summary>
protected virtual void OnRunningNodeChanged(object? sender, string? nodeName)
{
// Ignore if regular progress updates started
if (sender is not ComfyTask { HasProgressUpdateStarted: false })
var task = sender as ComfyTask;
if (task == null)
{
return;
}

// Ignore if regular progress updates started, unless the running node is different from the one reporting progress
if (task.HasProgressUpdateStarted && task.LastProgressUpdate?.RunningNode == nodeName)
{
return;
}
Expand Down Expand Up @@ -906,7 +912,7 @@ public ModuleApplyStepEventArgs ToModuleApplyStepEventArgs()
{
Builder = Builder,
IsEnabledOverrides = overrides,
FilesToTransfer = FilesToTransfer
FilesToTransfer = FilesToTransfer,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ RunningPackageService runningPackageService
/// <inheritdoc />
protected override void BuildPrompt(BuildPromptEventArgs args)
{
var applyArgs = args.ToModuleApplyStepEventArgs();
var builder = args.Builder;

builder.Connections.Seed = args.SeedOverride switch
{
{ } seed => Convert.ToUInt64(seed),
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
};

// Load models
ModelCardViewModel.ApplyStep(args);
ModelCardViewModel.ApplyStep(applyArgs);

// Setup latent from image
var imageLoad = builder.Nodes.AddTypedNode(
Expand All @@ -57,22 +58,24 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
Name = builder.Nodes.GetUniqueName("ControlNet_LoadImage"),
Image =
SelectImageCardViewModel.ImageSource?.GetHashGuidFileNameCached("Inference")
?? throw new ValidationException()
?? throw new ValidationException(),
}
);
builder.Connections.Primary = imageLoad.Output1;
builder.Connections.PrimarySize = SelectImageCardViewModel.CurrentBitmapSize;

BatchSizeCardViewModel.ApplyStep(args);
BatchSizeCardViewModel.ApplyStep(applyArgs);

SelectImageCardViewModel.ApplyStep(args);
SelectImageCardViewModel.ApplyStep(applyArgs);

PromptCardViewModel.ApplyStep(args);
PromptCardViewModel.ApplyStep(applyArgs);

SamplerCardViewModel.ApplyStep(args);
SamplerCardViewModel.ApplyStep(applyArgs);

applyArgs.InvokeAllPreOutputActions();

// Animated webp output
VideoOutputSettingsCardViewModel.ApplyStep(args);
VideoOutputSettingsCardViewModel.ApplyStep(applyArgs);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ RunningPackageService runningPackageService
samplerCard.IsSamplerSelectionEnabled = true;
samplerCard.IsSchedulerSelectionEnabled = true;
samplerCard.DenoiseStrength = 1.0d;
samplerCard.EnableAddons = false;
samplerCard.EnableAddons = true;
samplerCard.IsLengthEnabled = true;
samplerCard.Width = 832;
samplerCard.Height = 480;
Expand All @@ -70,8 +70,8 @@ RunningPackageService runningPackageService

BatchSizeCardViewModel = vmFactory.Get<BatchSizeCardViewModel>();

VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(
vm => vm.Fps = 16.0d
VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(vm =>
vm.Fps = 16.0d
);

StackCardViewModel = vmFactory.Get<StackCardViewModel>();
Expand All @@ -89,16 +89,17 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
{
base.BuildPrompt(args);

var applyArgs = args.ToModuleApplyStepEventArgs();
var builder = args.Builder;

builder.Connections.Seed = args.SeedOverride switch
{
{ } seed => Convert.ToUInt64(seed),
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
};

// Load models
ModelCardViewModel.ApplyStep(args);
ModelCardViewModel.ApplyStep(applyArgs);

builder.SetupEmptyLatentSource(
SamplerCardViewModel.Width,
Expand All @@ -109,14 +110,16 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
LatentType.Hunyuan
);

BatchSizeCardViewModel.ApplyStep(args);
BatchSizeCardViewModel.ApplyStep(applyArgs);

PromptCardViewModel.ApplyStep(args);
PromptCardViewModel.ApplyStep(applyArgs);

SamplerCardViewModel.ApplyStep(args);
SamplerCardViewModel.ApplyStep(applyArgs);

applyArgs.InvokeAllPreOutputActions();

// Animated webp output
VideoOutputSettingsCardViewModel.ApplyStep(args);
VideoOutputSettingsCardViewModel.ApplyStep(applyArgs);
}

/// <inheritdoc />
Expand Down Expand Up @@ -165,13 +168,13 @@ CancellationToken cancellationToken
OutputNodeNames = buildPromptArgs.Builder.Connections.OutputNodeNames.ToArray(),
Parameters = SaveStateToParameters(new GenerationParameters()) with
{
Seed = Convert.ToUInt64(seed)
Seed = Convert.ToUInt64(seed),
},
Project = inferenceProject,
FilesToTransfer = buildPromptArgs.FilesToTransfer,
BatchIndex = i,
// Only clear output images on the first batch
ClearOutputImages = i == 0
ClearOutputImages = i == 0,
};

batchArgs.Add(generationArgs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Injectio.Attributes;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Models.Api.Comfy;
Expand Down Expand Up @@ -34,6 +36,14 @@ TabContext tabContext

public override void ApplyStep(ModuleApplyStepEventArgs e)
{
if (EnableAddons)
{
foreach (var module in ModulesCardViewModel.Cards.OfType<ModuleBase>())
{
module.ApplyStep(e);
}
}

// Set primary sampler and scheduler
var primarySampler = SelectedSampler ?? throw new ValidationException("Sampler not selected");
e.Builder.Connections.PrimarySampler = primarySampler;
Expand Down
13 changes: 9 additions & 4 deletions StabilityMatrix.Core/Models/Api/Comfy/Nodes/ComfyNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Text.Json.Serialization;
using OneOf;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Extensions;
Expand Down Expand Up @@ -67,17 +68,21 @@ public record TiledVAEDecode : ComfyTypedNodeBase<ImageNodeConnection>
{
public required LatentNodeConnection Samples { get; init; }
public required VAENodeConnection Vae { get; init; }

[Range(64, 4096)]
[JsonPropertyName("tile_size")]
public int TileSize { get; init; } = 512;

[Range(0, 4096)]
[JsonPropertyName("overlap")]
public int Overlap { get; init; } = 64;

[Range(8, 4096)]
[JsonPropertyName("temporal_size")]
public int TemporalSize { get; init; } = 64;

[Range(4, 4096)]
[JsonPropertyName("temporal_overlap")]
public int TemporalOverlap { get; init; } = 8;
}

Expand Down
Loading