Skip to content

Commit ce0861c

Browse files
committed
fix: sync WAN viewmodel and ComfyClient after cleanup
1 parent 2600b4e commit ce0861c

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceWanTextToVideoViewModel.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ RunningPackageService runningPackageService
7070

7171
BatchSizeCardViewModel = vmFactory.Get<BatchSizeCardViewModel>();
7272

73-
VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(
74-
vm => vm.Fps = 16.0d
73+
VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(vm =>
74+
vm.Fps = 16.0d
7575
);
7676

7777
StackCardViewModel = vmFactory.Get<StackCardViewModel>();
@@ -94,7 +94,7 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
9494
builder.Connections.Seed = args.SeedOverride switch
9595
{
9696
{ } seed => Convert.ToUInt64(seed),
97-
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
97+
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
9898
};
9999

100100
// Load models
@@ -115,14 +115,13 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
115115

116116
SamplerCardViewModel.ApplyStep(args);
117117

118-
// ADD THIS - Apply TiledVAE module
118+
// Apply TiledVAE module
119119
TiledVAEModule.ApplyStep(args);
120120

121-
// ADD THIS LINE - Invoke pre-output actions BEFORE video output!
121+
// Invoke pre-output actions BEFORE video output!
122122
args.Builder.InvokeAllPreOutputActions();
123123

124124
VideoOutputSettingsCardViewModel.ApplyStep(args);
125-
126125
}
127126

128127
/// <inheritdoc />
@@ -171,13 +170,13 @@ CancellationToken cancellationToken
171170
OutputNodeNames = buildPromptArgs.Builder.Connections.OutputNodeNames.ToArray(),
172171
Parameters = SaveStateToParameters(new GenerationParameters()) with
173172
{
174-
Seed = Convert.ToUInt64(seed)
173+
Seed = Convert.ToUInt64(seed),
175174
},
176175
Project = inferenceProject,
177176
FilesToTransfer = buildPromptArgs.FilesToTransfer,
178177
BatchIndex = i,
179178
// Only clear output images on the first batch
180-
ClearOutputImages = i == 0
179+
ClearOutputImages = i == 0,
181180
};
182181

183182
batchArgs.Add(generationArgs);

StabilityMatrix.Core/Inference/ComfyClient.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ public class ComfyClient : InferenceClientBase
2929
private readonly IComfyApi comfyApi;
3030
private bool isDisposed;
3131

32-
private readonly JsonSerializerOptions jsonSerializerOptions =
33-
new()
32+
private readonly JsonSerializerOptions jsonSerializerOptions = new()
33+
{
34+
PropertyNamingPolicy = JsonNamingPolicies.SnakeCaseLower,
35+
Converters =
3436
{
35-
PropertyNamingPolicy = JsonNamingPolicies.SnakeCaseLower,
36-
Converters =
37-
{
38-
new NodeConnectionBaseJsonConverter(),
39-
new OneOfJsonConverter<string, StringNodeConnection>()
40-
}
41-
};
37+
new NodeConnectionBaseJsonConverter(),
38+
new OneOfJsonConverter<string, StringNodeConnection>(),
39+
},
40+
};
4241

4342
// ReSharper disable once MemberCanBePrivate.Global
4443
public string ClientId { get; } = Guid.NewGuid().ToString();
@@ -111,20 +110,20 @@ public ComfyClient(IApiFactory apiFactory, Uri baseAddress)
111110
{
112111
Scheme = "ws",
113112
Path = "/ws",
114-
Query = $"clientId={ClientId}"
113+
Query = $"clientId={ClientId}",
115114
}.Uri;
116115

117116
webSocketClient = new WebsocketClient(wsUri)
118117
{
119118
Name = nameof(ComfyClient),
120-
ReconnectTimeout = TimeSpan.FromSeconds(30)
119+
ReconnectTimeout = TimeSpan.FromSeconds(30),
121120
};
122121

123-
webSocketClient.DisconnectionHappened.Subscribe(
124-
info => Logger.Info("Websocket Disconnected, ({Type})", info.Type)
122+
webSocketClient.DisconnectionHappened.Subscribe(info =>
123+
Logger.Info("Websocket Disconnected, ({Type})", info.Type)
125124
);
126-
webSocketClient.ReconnectionHappened.Subscribe(
127-
info => Logger.Info("Websocket Reconnected, ({Type})", info.Type)
125+
webSocketClient.ReconnectionHappened.Subscribe(info =>
126+
Logger.Info("Websocket Reconnected, ({Type})", info.Type)
128127
);
129128

130129
webSocketClient.MessageReceived.Subscribe(OnMessageReceived);
@@ -287,7 +286,7 @@ private void HandleBinaryMessage(byte[] data)
287286
Array.Reverse(typeBytes);
288287
}*/
289288

290-
PreviewImageReceived?.Invoke(this, new ComfyWebSocketImageData { ImageBytes = data[8..], });
289+
PreviewImageReceived?.Invoke(this, new ComfyWebSocketImageData { ImageBytes = data[8..] });
291290
}
292291

293292
public override async Task ConnectAsync(CancellationToken cancellationToken = default)
@@ -326,21 +325,23 @@ public override async Task CloseAsync(CancellationToken cancellationToken = defa
326325
await webSocketClient.Stop(WebSocketCloseStatus.NormalClosure, string.Empty).ConfigureAwait(false);
327326
}
328327

329-
public async Task<ComfyTask> QueuePromptAsync(
330-
Dictionary<string, ComfyNode> nodes,
331-
CancellationToken cancellationToken = default
332-
)
333-
{
334-
var request = new ComfyPromptRequest { ClientId = ClientId, Prompt = nodes };
328+
public async Task<ComfyTask> QueuePromptAsync(
329+
Dictionary<string, ComfyNode> nodes,
330+
CancellationToken cancellationToken = default
331+
)
332+
{
333+
var request = new ComfyPromptRequest { ClientId = ClientId, Prompt = nodes };
335334

336-
var result = await comfyApi.PostPrompt(request, cancellationToken).ConfigureAwait(false);
335+
var result = await comfyApi.PostPrompt(request, cancellationToken).ConfigureAwait(false);
337336

338-
var task = new ComfyTask(result.PromptId);
339-
PromptTasks.TryAdd(result.PromptId, task);
340-
currentPromptTask = task;
337+
// Add task to dictionary and set it as the current task
338+
var task = new ComfyTask(result.PromptId);
339+
PromptTasks.TryAdd(result.PromptId, task);
340+
currentPromptTask = task;
341+
342+
return task;
343+
}
341344

342-
return task;
343-
}
344345
public async Task InterruptPromptAsync(CancellationToken cancellationToken = default)
345346
{
346347
await comfyApi.PostInterrupt(cancellationToken).ConfigureAwait(false);

0 commit comments

Comments
 (0)