From 38be8da27f1f84ccadc99dd6e02ca42ae5292dc0 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sat, 30 Sep 2023 16:22:39 -0400 Subject: [PATCH 01/14] Remove double logging in DataStoreLoggerTarget --- .../LogViewer/DataStoreLoggerTarget.cs | 4 ---- StabilityMatrix.Avalonia/App.axaml.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/StabilityMatrix.Avalonia.Diagnostics/LogViewer/DataStoreLoggerTarget.cs b/StabilityMatrix.Avalonia.Diagnostics/LogViewer/DataStoreLoggerTarget.cs index 22646b04..da8f501a 100644 --- a/StabilityMatrix.Avalonia.Diagnostics/LogViewer/DataStoreLoggerTarget.cs +++ b/StabilityMatrix.Avalonia.Diagnostics/LogViewer/DataStoreLoggerTarget.cs @@ -71,10 +71,6 @@ public class DataStoreLoggerTarget : TargetWithLayout Color = _config!.Colors[logLevel], } ); - - Debug.WriteLine( - $"--- [{logLevel.ToString()[..3]}] {message} - {logEvent.Exception?.Message ?? "no error"}" - ); } #endregion diff --git a/StabilityMatrix.Avalonia/App.axaml.cs b/StabilityMatrix.Avalonia/App.axaml.cs index 36a56e93..bab40548 100644 --- a/StabilityMatrix.Avalonia/App.axaml.cs +++ b/StabilityMatrix.Avalonia/App.axaml.cs @@ -699,7 +699,14 @@ public sealed class App : Application { var debugTarget = builder .ForTarget("console") - .WriteTo(new DebuggerTarget { Layout = "${message}" }) + .WriteTo( + new DebuggerTarget + { + Layout = + "[${level:format=TriLetter}] " + + "${callsite:includeNamespace=false:captureStackTrace=false}: ${message}" + } + ) .WithAsync(); var fileTarget = builder From cd8d7816c39bb775b153d49ebdada000f52e3b34 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sat, 30 Sep 2023 16:34:30 -0400 Subject: [PATCH 02/14] Ignore websocket errors for sentry --- StabilityMatrix.Avalonia/Program.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/StabilityMatrix.Avalonia/Program.cs b/StabilityMatrix.Avalonia/Program.cs index b8c0cd00..16c0c3fd 100644 --- a/StabilityMatrix.Avalonia/Program.cs +++ b/StabilityMatrix.Avalonia/Program.cs @@ -176,6 +176,19 @@ public class Program #if DEBUG o.Environment = "Development"; #endif + // Filters + o.SetBeforeSend( + (sentryEvent, _) => + { + // Ignore websocket errors from ComfyClient + if (sentryEvent.Logger == "Websocket.Client.WebsocketClient") + { + return null; + } + + return sentryEvent; + } + ); }); } From 66a394b31d6c2b8b4d47a9b56eabb8e44ab02a2f Mon Sep 17 00:00:00 2001 From: Ionite Date: Sat, 30 Sep 2023 16:35:52 -0400 Subject: [PATCH 03/14] Some cleanup --- StabilityMatrix.Avalonia/App.axaml.cs | 17 ----------------- StabilityMatrix.Core/Inference/ComfyClient.cs | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/StabilityMatrix.Avalonia/App.axaml.cs b/StabilityMatrix.Avalonia/App.axaml.cs index bab40548..2633c3f0 100644 --- a/StabilityMatrix.Avalonia/App.axaml.cs +++ b/StabilityMatrix.Avalonia/App.axaml.cs @@ -17,9 +17,7 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; -using Avalonia.Controls.Primitives; using Avalonia.Input.Platform; -using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media.Imaging; using Avalonia.Platform; @@ -42,7 +40,6 @@ using Polly.Timeout; using Refit; using Sentry; using StabilityMatrix.Avalonia.Controls; -using StabilityMatrix.Avalonia.Controls.CodeCompletion; using StabilityMatrix.Avalonia.DesignData; using StabilityMatrix.Avalonia.Helpers; using StabilityMatrix.Avalonia.Languages; @@ -65,7 +62,6 @@ using StabilityMatrix.Avalonia.Views.Settings; using StabilityMatrix.Core.Api; using StabilityMatrix.Core.Converters.Json; using StabilityMatrix.Core.Database; -using StabilityMatrix.Core.Exceptions; using StabilityMatrix.Core.Extensions; using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper.Cache; @@ -81,7 +77,6 @@ using StabilityMatrix.Core.Services; using StabilityMatrix.Core.Updater; using Application = Avalonia.Application; using DrawingColor = System.Drawing.Color; -using InferenceTextToImageView = StabilityMatrix.Avalonia.Views.Inference.InferenceTextToImageView; using LogLevel = Microsoft.Extensions.Logging.LogLevel; namespace StabilityMatrix.Avalonia; @@ -762,18 +757,6 @@ public sealed class App : Application o.MinimumBreadcrumbLevel = NLog.LogLevel.Debug; // Error and higher is sent as event (default is Error) o.MinimumEventLevel = NLog.LogLevel.Error; - // Filters - o.SetBeforeSend( - (sentryEvent, _) => - { - if (sentryEvent.Logger == "Websocket.Client.WebsocketClient") - { - return null; - } - - return sentryEvent; - } - ); }); } diff --git a/StabilityMatrix.Core/Inference/ComfyClient.cs b/StabilityMatrix.Core/Inference/ComfyClient.cs index f4b21b6a..15433b5d 100644 --- a/StabilityMatrix.Core/Inference/ComfyClient.cs +++ b/StabilityMatrix.Core/Inference/ComfyClient.cs @@ -83,7 +83,7 @@ public class ComfyClient : InferenceClientBase webSocketClient = new WebsocketClient(wsUri) { - Name = "ComfyClient", + Name = nameof(ComfyClient), ReconnectTimeout = TimeSpan.FromSeconds(30) }; From 8f4536ef4c16abfc1d08b2ac080327b8a0d439c0 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 03:02:51 -0400 Subject: [PATCH 04/14] Add Italian language option --- .../Languages/Cultures.cs | 3 +- .../Languages/Resources.it-it.resx | 683 ++++++++++++++++++ 2 files changed, 685 insertions(+), 1 deletion(-) create mode 100644 StabilityMatrix.Avalonia/Languages/Resources.it-it.resx diff --git a/StabilityMatrix.Avalonia/Languages/Cultures.cs b/StabilityMatrix.Avalonia/Languages/Cultures.cs index e31d4695..b512d2e8 100644 --- a/StabilityMatrix.Avalonia/Languages/Cultures.cs +++ b/StabilityMatrix.Avalonia/Languages/Cultures.cs @@ -21,7 +21,8 @@ public static class Cultures ["en-US"] = Default, ["ja-JP"] = new("ja-JP"), ["zh-Hans"] = new("zh-Hans"), - ["zh-Hant"] = new("zh-Hant") + ["zh-Hant"] = new("zh-Hant"), + ["it-IT"] = new("it-IT") }; public static IReadOnlyList SupportedCultures => diff --git a/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx b/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx new file mode 100644 index 00000000..cadda8ef --- /dev/null +++ b/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx @@ -0,0 +1,683 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Avvia + + + Esci + + + Salva + + + Cancella + + + Lingua + + + E' richiesto il riavvio per rendere effettivi i cambiamenti + + + Riavvia + + + Riavvia Dopo + + + Riavvio Richiesto + + + Pacchetto Sconosciuto + + + Importa + + + Tipologia Pacchetto + + + Versione + + + Tipologia Versione + + + Releases + + + Branches + + + Trascina qui i checkpoint per importarli + + + Accentuazione + + + Attenuazione + + + Embeddings / Inversione Testuale + I'm not sure I'll translate this term because it is specifically contextual to Stable Diffusion, and it may confuse several users who are already using it. + + + Reti (Lora / LyCORIS) + + + Commenti + + + Mostra la griglia di pixel a livelli di zoom elevati + + + Steps + + + Steps - Base + + + Steps - Refiner + + + Scala CFG + + + Valore di Denoising + + + Larghezza + + + Altezza + + + Refiner + + + VAE + + + Modello + + + Connetti + + + In connessione... + + + Chiudi + + + In attesa della connessione... + + + Aggiornamento Disponibile + + + Diventa un Patreon + + + Unisciti al Server Discord + + + Scaricamenti + + + Installa + + + Salta la configurazione iniziale + + + Si è verificato un errore imprevisto + + + Esci dall'Applicazione + + + Nome da Visualizzare + + + Esiste già un'installazione con questo nome. + + + Scegli un nome diverso o seleziona un percorso di installazione diverso. + + + Opzioni Avanzate + + + Commit + + + Strategia Cartella Modello Condiviso + + + Versione PyTorch + + + Chiudi la finestra di dialogo al termine + + + Cartella dei Dati + + + Qui vengono installati i modelli checkpoint, le LORA, l'interfaccia utente Web, le impostazioni ecc. + + + Potresti riscontrare errori quando utilizzi un'unità FAT32 o exFAT. Seleziona un'unità diversa per un'esperienza più fluida. + + + Modalità Portable + + + In Modalità Portable, tutti i dati e le impostazioni verranno archiviati nella stessa directory dell'applicazione. Potrai spostare l'applicazione con la sua cartella 'Dati' in una posizione o computer diversi. + + + Continua + + + Immagine Precedente + + + Immagine Successiva + + + Descrizione Modello + + + E' disponibile una nuova versione di Stability Matrix! + Maybe a variable with the {appname} would be a better solution? + + + Importa più Recente - + + + Tutte le Versioni + + + Cerca modelli, #tags, o @utenti + + + Cerca + + + Ordina + + + Periodo + + + Tipo di Modello + + + Modello Base + + + Mostra Contenuti NSFW + + + Dati forniti da CivitAI + + + Pagina + + + Prima Pagina + + + Pagina Precedente + + + Pagina Successiva + + + Ultima Pagina + + + Rinomina + + + Cancella + + + Apri su CivitAI + + + Modello Collegato + + + Modello Locale + + + Mostra in Explorer + + + Nuovo + + + Cartella + + + Rilascia il file qui per importarlo + + + Recupera i metadati durante l'importazione + + + Cerca metadati collegati sulle nuove importazioni locali + + + Indicizzazione... + + + Cartella Modelli + + + Categorie + + + Iniziamo + + + Ho letto e acconsento al + + + Contratto di Licenza. + + + Trova i Metadati Collegati + + + Mostra Immagini del Modello + + + Aspetto + + + Tema + + + Gestione Checkpoint + + + Rimuovi allo spegnimento i collegamenti simbolici alla directory dei checkpoint condivisi + + + Seleziona questa opzione se riscontri problemi nello spostamento di Stability Matrix su un'altra unità + + + Reimposta la Cache dei Checkpoint + + + Ricostruisci la cache dei checkpoint installati. Da utilizzare se i checkpoint sono etichettati in modo errato nel Browser Modello + + + Ambiente del Pacchetto + + + Modifica + + + Variabili Ambiente + + + Python Incorporato + + + Controlla Versione + + + Integrazioni + + + Discord Rich Presence + + + Sistema + + + Aggiungi Stability Matrix al Menù Start + + + Utilizza la posizione corrente, puoi eseguirla di nuovo se sposti l'app + + + Disponibile solo su Windows + + + Aggiungi per l'Utente Corrente + + + Aggiungi per Tutti gli Utenti + + + Seleziona una nuova Cartella Dati + + + Non sposta i dati esistenti + + + Seleziona Cartella + + + Informazioni + + + Stability Matrix + + + Informazioni sulla Licenza e Open Source + + + Fai clic su Avvia per iniziare! + + + Ferma + + + Manda Input + + + Input + + + Invia + + + Input richiesto + + + Confermi? + + + Si + + + No + + + Apri la Web UI + + + Benvenuto su Stability Matrix! + + + Scegli la tua interfaccia preferita e clicca su Installa per inziare + + + Installazione in corso + + + Procediamo alla pagina di Avvio + + + Download del pacchetto in corso... + + + Download completato + + + Installazione completata + + + Installazione dei prerequisiti... + + + Installazione requisiti del pacchetto... + + + Apri in Explorer + + + Apri sul Finder + + + Disinstalla + + + Controlla gli Aggiornamenti + + + Aggiorna + + + Aggiungi un Pacchetto + + + Aggiungi un pacchetto per iniziare! + + + Nome + + + Valore + + + Rimuovi + + + Dettagli + + + Stack di chiamate + + + Eccezione interna + + + Cerca... + + + OK + + + Riprova + + + Informazioni Versione Python + + + Riavvia + + + Conferma Cancellazione + + + Ciò eliminerà la cartella del pacchetto e tutto il suo contenuto, comprese eventuali immagini e file generati che potresti aver aggiunto. + + + Disinstallazione del pacchetto in corso... + + + Pacchetto Disinstallato + + + Impossibile eliminare alcuni file. Chiudi tutti i file aperti nella directory del pacchetto e riprova. + + + Tipo di pacchetto non valido + + + Aggiornamento {0} + + + Aggiornamento Completato + + + {0} è stato aggiornato all'ultima versione + + + Errore aggiornamento {0} + + + Aggiornamento fallito + + + Apri nel Browser + + + Errore installazione pacchetto + + + Branch + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 6b8b8ded289c71f71985287952f9c0a67c5a7e78 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 18:46:00 -0400 Subject: [PATCH 05/14] Handle errors in interrupt prompt --- .../Base/InferenceGenerationViewModelBase.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index c17bde51..0b56b8c2 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -103,19 +103,22 @@ public abstract partial class InferenceGenerationViewModelBase // Connect preview image handler client.PreviewImageReceived += OnPreviewImageReceived; + // Register to interrupt if user cancels + await using var promptInterrupt = cancellationToken.Register(() => + { + Logger.Info("Cancelling prompt"); + client + .InterruptPromptAsync(new CancellationTokenSource(5000).Token) + .SafeFireAndForget(ex => + { + Logger.Warn(ex, "Error while interrupting prompt"); + }); + }); + ComfyTask? promptTask = null; try { - // Register to interrupt if user cancels - cancellationToken.Register(() => - { - Logger.Info("Cancelling prompt"); - client - .InterruptPromptAsync(new CancellationTokenSource(5000).Token) - .SafeFireAndForget(); - }); - try { promptTask = await client.QueuePromptAsync(nodes, cancellationToken); @@ -140,6 +143,9 @@ public abstract partial class InferenceGenerationViewModelBase cancellationToken ); + // Disable cancellation + await promptInterrupt.DisposeAsync(); + ImageGalleryCardViewModel.ImageSources.Clear(); if ( From 3b5691c90f7c03ab373a2221af8534e50764b1e0 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 18:47:25 -0400 Subject: [PATCH 06/14] Allow spaces in extra network tokens --- StabilityMatrix.Avalonia/Assets/ImagePrompt.tmLanguage.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/StabilityMatrix.Avalonia/Assets/ImagePrompt.tmLanguage.json b/StabilityMatrix.Avalonia/Assets/ImagePrompt.tmLanguage.json index d06b1efc..fdf0964e 100644 --- a/StabilityMatrix.Avalonia/Assets/ImagePrompt.tmLanguage.json +++ b/StabilityMatrix.Avalonia/Assets/ImagePrompt.tmLanguage.json @@ -133,7 +133,7 @@ "name": "meta.structure.network.prompt", "patterns": [ { - "match": "(?<=\\<)([^,:\\<\\> ]+)(:)([^,:\\<\\> ]+)(:)([-+]?\\d+(?:\\.\\d+)?)", + "match": "(?<=\\<)([^,:\\<\\>]+)(:)([^,:\\<\\>]+)(:)([-+]?\\d+(?:\\.\\d+)?)", "captures": { "1": { "name": "meta.embedded.network.type.prompt" @@ -153,7 +153,7 @@ } }, { - "match": "(?<=\\<)([^,:\\<\\> ]+)(:)([^,:\\<\\> ]+)?", + "match": "(?<=\\<)([^,:\\<\\>]+)(:)([^,:\\<\\>]+)?", "captures": { "1": { "name": "meta.embedded.network.type.prompt" @@ -167,7 +167,7 @@ } }, { - "match": "(?<=\\<)([^,:\\<\\> ]+)", + "match": "(?<=\\<)([^,:\\<\\>]+)", "captures": { "1": { "name": "meta.embedded.network.type.prompt" From ed31e7646312c77b07e847ad287d3206505e968b Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 19:21:21 -0400 Subject: [PATCH 07/14] Move registration dispose to finally --- .../ViewModels/Base/InferenceGenerationViewModelBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index 0b56b8c2..6fec5b7f 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -104,7 +104,7 @@ public abstract partial class InferenceGenerationViewModelBase client.PreviewImageReceived += OnPreviewImageReceived; // Register to interrupt if user cancels - await using var promptInterrupt = cancellationToken.Register(() => + var promptInterrupt = cancellationToken.Register(() => { Logger.Info("Cancelling prompt"); client @@ -173,6 +173,7 @@ public abstract partial class InferenceGenerationViewModelBase // Cleanup tasks promptTask?.Dispose(); + await promptInterrupt.DisposeAsync(); } } From af88003829c98a9a67a1110a8bf3a7c28973610b Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 21:04:00 -0400 Subject: [PATCH 08/14] Check inferenceoutput link before making --- StabilityMatrix.Core/Models/Packages/ComfyUI.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs index 7e1e4e58..a7a3126e 100644 --- a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs @@ -449,6 +449,18 @@ public class ComfyUI : BaseGitPackage var sharedInferenceDir = SettingsManager.ImagesInferenceDirectory; + if (sharedInferenceDir.IsSymbolicLink) + { + if (sharedInferenceDir.Info.ResolveLinkTarget(true) == sharedInferenceDir.Info) + { + // Already valid link, skip + return; + } + + // Otherwise delete so we don't have to move files + await sharedInferenceDir.DeleteAsync(false).ConfigureAwait(false); + } + await Task.Run(() => { Helper.SharedFolders.CreateLinkOrJunctionWithMove(sharedInferenceDir, inferenceDir); From b13f9e68e06b7006f5bf6033ed0aa752112bb839 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 1 Oct 2023 21:04:33 -0400 Subject: [PATCH 09/14] Fix directory check target --- StabilityMatrix.Core/Models/Packages/ComfyUI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs index a7a3126e..6a7e5940 100644 --- a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs @@ -451,7 +451,7 @@ public class ComfyUI : BaseGitPackage if (sharedInferenceDir.IsSymbolicLink) { - if (sharedInferenceDir.Info.ResolveLinkTarget(true) == sharedInferenceDir.Info) + if (inferenceDir.Info.ResolveLinkTarget(true) == sharedInferenceDir.Info) { // Already valid link, skip return; From 14bfb9ecdc6328ed963d616c14cac8887813dd32 Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 2 Oct 2023 01:17:32 -0400 Subject: [PATCH 10/14] Fix symlink logic --- StabilityMatrix.Core/Models/Packages/ComfyUI.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs index 6a7e5940..0e773cb3 100644 --- a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs @@ -449,9 +449,9 @@ public class ComfyUI : BaseGitPackage var sharedInferenceDir = SettingsManager.ImagesInferenceDirectory; - if (sharedInferenceDir.IsSymbolicLink) + if (inferenceDir.IsSymbolicLink) { - if (inferenceDir.Info.ResolveLinkTarget(true) == sharedInferenceDir.Info) + if (inferenceDir.Info.ResolveLinkTarget(true)?.FullName == sharedInferenceDir.FullPath) { // Already valid link, skip return; From dd39428c14a406623e9a4bb20b057ab22692e18f Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 2 Oct 2023 01:17:50 -0400 Subject: [PATCH 11/14] Add progress reporting for running node changed events --- .../Base/InferenceGenerationViewModelBase.cs | 20 +++++++++++++ StabilityMatrix.Core/Inference/ComfyTask.cs | 29 ++++++++++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index 6fec5b7f..1b5ac8fc 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -340,6 +340,26 @@ public abstract partial class InferenceGenerationViewModelBase }); } + /// + /// Handles the node executing updates received event from the websocket. + /// + protected virtual void OnRunningNodeChanged(object? sender, string? nodeName) + { + // Ignore if regular progress updates started + if (sender is not ComfyTask { LastProgressUpdate: null }) + { + return; + } + + Dispatcher.UIThread.Post(() => + { + OutputProgress.IsIndeterminate = true; + OutputProgress.Value = 100; + OutputProgress.Maximum = 100; + OutputProgress.Text = nodeName; + }); + } + public class ImageGenerationEventArgs : EventArgs { public required ComfyClient Client { get; init; } diff --git a/StabilityMatrix.Core/Inference/ComfyTask.cs b/StabilityMatrix.Core/Inference/ComfyTask.cs index 0fbd613e..95bfcb7c 100644 --- a/StabilityMatrix.Core/Inference/ComfyTask.cs +++ b/StabilityMatrix.Core/Inference/ComfyTask.cs @@ -1,4 +1,4 @@ -using System.Reactive; +using System.ComponentModel; using StabilityMatrix.Core.Models.Api.Comfy.WebSocketData; namespace StabilityMatrix.Core.Inference; @@ -6,24 +6,39 @@ namespace StabilityMatrix.Core.Inference; public class ComfyTask : TaskCompletionSource, IDisposable { public string Id { get; set; } - - public string? RunningNode { get; set; } + + private string? runningNode; + public string? RunningNode + { + get => runningNode; + set + { + runningNode = value; + RunningNodeChanged?.Invoke(this, value); + } + } + + public ComfyProgressUpdateEventArgs? LastProgressUpdate { get; private set; } public EventHandler? ProgressUpdate; - + + public event EventHandler? RunningNodeChanged; + public ComfyTask(string id) { Id = id; } - + /// /// Handler for progress updates /// public void OnProgressUpdate(ComfyWebSocketProgressData update) { - ProgressUpdate?.Invoke(this, new ComfyProgressUpdateEventArgs(update.Value, update.Max, Id, RunningNode)); + var args = new ComfyProgressUpdateEventArgs(update.Value, update.Max, Id, RunningNode); + ProgressUpdate?.Invoke(this, args); + LastProgressUpdate = args; } - + /// public void Dispose() { From b2f03299bd77ae38814cb538913efe0f031d7c54 Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 2 Oct 2023 01:26:26 -0400 Subject: [PATCH 12/14] Actually subscribe the event handler --- .../ViewModels/Base/InferenceGenerationViewModelBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index 1b5ac8fc..f32a93b8 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -132,6 +132,7 @@ public abstract partial class InferenceGenerationViewModelBase // Register progress handler promptTask.ProgressUpdate += OnProgressUpdateReceived; + promptTask.RunningNodeChanged += OnRunningNodeChanged; // Wait for prompt to finish await promptTask.Task.WaitAsync(cancellationToken); From e68a8512efb0818c816ad946881f66baf66f38ad Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 2 Oct 2023 01:28:20 -0400 Subject: [PATCH 13/14] Add indeterminate bindings to progress bars --- .../Views/Inference/InferenceImageUpscaleView.axaml | 1 + .../Views/Inference/InferenceTextToImageView.axaml | 1 + 2 files changed, 2 insertions(+) diff --git a/StabilityMatrix.Avalonia/Views/Inference/InferenceImageUpscaleView.axaml b/StabilityMatrix.Avalonia/Views/Inference/InferenceImageUpscaleView.axaml index c4e460ba..5e63c01e 100644 --- a/StabilityMatrix.Avalonia/Views/Inference/InferenceImageUpscaleView.axaml +++ b/StabilityMatrix.Avalonia/Views/Inference/InferenceImageUpscaleView.axaml @@ -148,6 +148,7 @@ Spacing="4"> From 48b81afc6816fb0ce137ab141a409de3aa5cb884 Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 2 Oct 2023 01:59:38 -0400 Subject: [PATCH 14/14] Fix interrupt handler disposed too early --- .../Base/InferenceGenerationViewModelBase.cs | 18 ++++++++++++++---- .../ViewModels/Base/ProgressViewModel.cs | 11 +++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index f32a93b8..7ee884e2 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -132,7 +132,19 @@ public abstract partial class InferenceGenerationViewModelBase // Register progress handler promptTask.ProgressUpdate += OnProgressUpdateReceived; - promptTask.RunningNodeChanged += OnRunningNodeChanged; + + // Delay attaching running node change handler to not show indeterminate progress + // if progress updates are received before the prompt starts + Task.Run( + async () => + { + await Task.Delay(200, cancellationToken); + // ReSharper disable once AccessToDisposedClosure + promptTask.RunningNodeChanged += OnRunningNodeChanged; + }, + cancellationToken + ) + .SafeFireAndForget(); // Wait for prompt to finish await promptTask.Task.WaitAsync(cancellationToken); @@ -166,15 +178,13 @@ public abstract partial class InferenceGenerationViewModelBase client.PreviewImageReceived -= OnPreviewImageReceived; // Clear progress - OutputProgress.Value = 0; - OutputProgress.Text = ""; + OutputProgress.ClearProgress(); ImageGalleryCardViewModel.PreviewImage?.Dispose(); ImageGalleryCardViewModel.PreviewImage = null; ImageGalleryCardViewModel.IsPreviewOverlayEnabled = false; // Cleanup tasks promptTask?.Dispose(); - await promptInterrupt.DisposeAsync(); } } diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs index cc0466e3..40375dfa 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs @@ -12,16 +12,23 @@ public partial class ProgressViewModel : ViewModelBase [ObservableProperty] private string? description; - + [ObservableProperty, NotifyPropertyChangedFor(nameof(IsProgressVisible))] private double value; [ObservableProperty] private double maximum = 100; - + [ObservableProperty, NotifyPropertyChangedFor(nameof(IsProgressVisible))] private bool isIndeterminate; public virtual bool IsProgressVisible => Value > 0 || IsIndeterminate; public virtual bool IsTextVisible => !string.IsNullOrWhiteSpace(Text); + + public void ClearProgress() + { + Value = 0; + Text = null; + IsIndeterminate = false; + } }