Skip to content

Commit

Permalink
Merge pull request #463 from LykosAI/main
Browse files Browse the repository at this point in the history
v2.8.3 Update
  • Loading branch information
ionite34 authored Feb 15, 2024
2 parents a0ff4a0 + c495f65 commit 69a2c08
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).

## v2.8.3
### Fixed
- Fixed user tokens read error causing failed downloads
- Failed downloads will now log error messages
- Fixed [#458](https://github.com/LykosAI/StabilityMatrix/issues/458) - Save Intermediate Image not working
- Fixed [#453](https://github.com/LykosAI/StabilityMatrix/issues/453) - Update Fooocus `--output-directory` argument to `--output-path`

## v2.8.2
### Added
- Added missing GFPGAN link to Automatic1111 packages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Management;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
Expand All @@ -15,7 +15,6 @@
using Avalonia.Threading;
using CommunityToolkit.Mvvm.Input;
using ExifLibrary;
using MetadataExtractor.Formats.Exif;
using NLog;
using Refit;
using SkiaSharp;
Expand All @@ -27,7 +26,6 @@
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.ViewModels.Inference;
using StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
using StabilityMatrix.Core.Animation;
using StabilityMatrix.Core.Exceptions;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Helper;
Expand Down Expand Up @@ -297,14 +295,18 @@ protected async Task RunGeneration(ImageGenerationEventArgs args, CancellationTo
Task.Run(
async () =>
{
var delayTime = 250 - (int)timer.ElapsedMilliseconds;
if (delayTime > 0)
try
{
await Task.Delay(delayTime, cancellationToken);
var delayTime = 250 - (int)timer.ElapsedMilliseconds;
if (delayTime > 0)
{
await Task.Delay(delayTime, cancellationToken);
}

// ReSharper disable once AccessToDisposedClosure
AttachRunningNodeChangedHandler(promptTask);
}

// ReSharper disable once AccessToDisposedClosure
AttachRunningNodeChangedHandler(promptTask);
catch (TaskCanceledException) { }
},
cancellationToken
)
Expand All @@ -328,10 +330,7 @@ await DialogHelper
// Get output images
var imageOutputs = await client.GetImagesForExecutedPromptAsync(promptTask.Id, cancellationToken);

if (
!imageOutputs.TryGetValue(args.OutputNodeNames[0], out var images)
|| images is not { Count: > 0 }
)
if (imageOutputs.Values.All(images => images is null or { Count: 0 }))
{
// No images match
notificationService.Show(
Expand All @@ -350,7 +349,7 @@ await DialogHelper
ImageGalleryCardViewModel.ImageSources.Clear();
}

var outputImages = await ProcessOutputImages(images, args);
var outputImages = await ProcessAllOutputImages(imageOutputs, args);

var notificationImage = outputImages.FirstOrDefault()?.LocalFile;

Expand Down Expand Up @@ -380,12 +379,34 @@ await notificationService.ShowAsync(
}
}

private async Task<IEnumerable<ImageSource>> ProcessAllOutputImages(
IReadOnlyDictionary<string, List<ComfyImage>?> images,
ImageGenerationEventArgs args
)
{
var results = new List<ImageSource>();

foreach (var (nodeName, imageList) in images)
{
if (imageList is null)
{
Logger.Warn("No images for node {NodeName}", nodeName);
continue;
}

results.AddRange(await ProcessOutputImages(imageList, args, nodeName.Replace('_', ' ')));
}

return results;
}

/// <summary>
/// Handles image output metadata for generation runs
/// </summary>
private async Task<List<ImageSource>> ProcessOutputImages(
IReadOnlyCollection<ComfyImage> images,
ImageGenerationEventArgs args
ImageGenerationEventArgs args,
string? imageLabel = null
)
{
var client = args.Client;
Expand Down Expand Up @@ -441,7 +462,7 @@ ImageGenerationEventArgs args
images.Count
);

outputImages.Add(new ImageSource(filePath));
outputImages.Add(new ImageSource(filePath) { Label = imageLabel });
EventManager.Instance.OnImageFileAdded(filePath);
}
else if (comfyImage.FileName.EndsWith(".webp"))
Expand Down Expand Up @@ -470,7 +491,7 @@ ImageGenerationEventArgs args
fileExtension: Path.GetExtension(comfyImage.FileName).Replace(".", "")
);

outputImages.Add(new ImageSource(filePath));
outputImages.Add(new ImageSource(filePath) { Label = imageLabel });
EventManager.Instance.OnImageFileAdded(filePath);
}
else
Expand All @@ -484,7 +505,7 @@ ImageGenerationEventArgs args
fileExtension: Path.GetExtension(comfyImage.FileName).Replace(".", "")
);

outputImages.Add(new ImageSource(filePath));
outputImages.Add(new ImageSource(filePath) { Label = imageLabel });
EventManager.Instance.OnImageFileAdded(filePath);
}
}
Expand Down Expand Up @@ -554,7 +575,12 @@ private async Task GenerateImage(
}
catch (OperationCanceledException)
{
Logger.Debug($"Image Generation Canceled");
Logger.Debug("Image Generation Canceled");
}
catch (ValidationException e)
{
Logger.Debug("Image Generation Validation Error: {Message}", e.Message);
notificationService.Show("Validation Error", e.Message, NotificationType.Error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Core/Models/Packages/Fooocus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ IPrerequisiteHelper prerequisiteHelper
Name = "Output Directory",
Type = LaunchOptionType.String,
Description = "Override the output directory",
Options = { "--output-directory" }
Options = { "--output-path" }
},
new LaunchOptionDefinition
{
Expand Down
2 changes: 2 additions & 0 deletions StabilityMatrix.Core/Models/TrackedDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ private void OnDownloadTaskCompleted(Task task)
return;
}

Logger.Warn(Exception, "Download {Download} failed", FileName);

OnProgressStateChanging(ProgressState.Failed);
ProgressState = ProgressState.Failed;
}
Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Core/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private async Task AddConditionalHeaders(HttpClient client, Uri url)
if (url.Host.Equals("civitai.com", StringComparison.OrdinalIgnoreCase))
{
// Add auth if we have it
if (await secretsManager.LoadAsync().ConfigureAwait(false) is { CivitApi: { } civitApi })
if (await secretsManager.SafeLoadAsync().ConfigureAwait(false) is { CivitApi: { } civitApi })
{
logger.LogTrace(
"Adding Civit auth header {Signature} for download {Url}",
Expand Down
6 changes: 1 addition & 5 deletions StabilityMatrix.Core/Services/SecretsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public async Task<Secrets> SafeLoadAsync()
}
catch (Exception e)
{
logger.LogWarning(
e,
"Failed to load secrets ({ExcType}), saving new instance",
e.GetType().Name
);
logger.LogError(e, "Failed to load secrets ({ExcType}), saving new instance", e.GetType().Name);

var secrets = new Secrets();
await SaveAsync(secrets).ConfigureAwait(false);
Expand Down

0 comments on commit 69a2c08

Please sign in to comment.