forked from LykosAI/StabilityMatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInferenceWanImageToVideoViewModel.cs
More file actions
89 lines (73 loc) · 3.04 KB
/
InferenceWanImageToVideoViewModel.cs
File metadata and controls
89 lines (73 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Injectio.Attributes;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.Views.Inference;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Avalonia.ViewModels.Inference;
[View(typeof(InferenceWanImageToVideoView), IsPersistent = true)]
[RegisterScoped<InferenceWanImageToVideoViewModel>, ManagedService]
public class InferenceWanImageToVideoViewModel : InferenceWanTextToVideoViewModel
{
public InferenceWanImageToVideoViewModel(
IServiceManager<ViewModelBase> vmFactory,
IInferenceClientManager inferenceClientManager,
INotificationService notificationService,
ISettingsManager settingsManager,
RunningPackageService runningPackageService
)
: base(vmFactory, inferenceClientManager, notificationService, settingsManager, runningPackageService)
{
SelectImageCardViewModel = vmFactory.Get<SelectImageCardViewModel>();
SamplerCardViewModel.IsDenoiseStrengthEnabled = true;
SamplerCardViewModel.Width = 512;
SamplerCardViewModel.Height = 512;
ModelCardViewModel.IsClipVisionEnabled = true;
}
[JsonPropertyName("ImageLoader")]
public SelectImageCardViewModel SelectImageCardViewModel { get; }
/// <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),
};
// Load models
ModelCardViewModel.ApplyStep(applyArgs);
// Setup latent from image
var imageLoad = builder.Nodes.AddTypedNode(
new ComfyNodeBuilder.LoadImage
{
Name = builder.Nodes.GetUniqueName("ControlNet_LoadImage"),
Image =
SelectImageCardViewModel.ImageSource?.GetHashGuidFileNameCached("Inference")
?? throw new ValidationException(),
}
);
builder.Connections.Primary = imageLoad.Output1;
builder.Connections.PrimarySize = SelectImageCardViewModel.CurrentBitmapSize;
BatchSizeCardViewModel.ApplyStep(applyArgs);
SelectImageCardViewModel.ApplyStep(applyArgs);
PromptCardViewModel.ApplyStep(applyArgs);
SamplerCardViewModel.ApplyStep(applyArgs);
applyArgs.InvokeAllPreOutputActions();
// Animated webp output
VideoOutputSettingsCardViewModel.ApplyStep(applyArgs);
}
/// <inheritdoc />
protected override IEnumerable<ImageSource> GetInputImages()
{
if (SelectImageCardViewModel.ImageSource is { } image)
{
yield return image;
}
}
}