Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o image-to-video
  • Loading branch information
mohnjiles committed Dec 19, 2023
2 parents 280fc8c + 724c3f4 commit 8165293
Show file tree
Hide file tree
Showing 23 changed files with 542 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .config/.csharpierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"printWidth": 120,
"printWidth": 110,
"preprocessorSymbolSets": ["", "DEBUG", "DEBUG,CODE_STYLE"]
}
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
]
},
"csharpier": {
"version": "0.26.4",
"version": "0.26.7",
"commands": [
"dotnet-csharpier"
]
}
}
}
}
1 change: 1 addition & 0 deletions .csharpierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
printWidth: 110
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ 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.7.4
### Changed
- Improved low disk space handling
### Fixed
- Fixed denoise strength in Inference Text to Image
- Fixed PathTooLongException for IPAdapter folders when using ComfyUI in Symlink mode
- Fixed configs and symlinks not being cleaned up when switched to the opposite mode
- Fixed model indexing stopping when encountering paths longer than 1021 bytes in length
- Fixed repeated nested folders being created in `Models/ControlNet` when using ComfyUI in Symlink mode. Existing folders will be repaired to their original structure on launch.

## v2.7.3
### Added
- Added missing IPAdapter and CLIP Vision folder links for ComfyUI
### Fixed
- Fixed UnicodeDecodeError when using extra_model_paths.yaml in ComfyUI on certain locales
- Fixed SDXL CLIP Vision model directory name conflict
- Fixed [#334](https://github.com/LykosAI/StabilityMatrix/issues/334) - Win32Exception if Settings are opened

## v2.7.2
### Changed
- Changed Symlink shared folder link targets for Automatic1111 and ComfyUI. From `ControlNet -> models/controlnet` to `ControlNet -> models/controlnet/ControlNet` and `T2IAdapter -> models/controlnet/T2IAdapter`.
Expand All @@ -18,7 +36,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2

## v2.7.1
### Added
- Added Turkish UI language option, thanks to Progresor for the translation
- Added Turkish UI language option, thanks to Progesor for the translation
### Fixed
- Fixed Inference Image to Image projects missing denoise strength setting

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Stability Matrix is now available in the following languages, thanks to our comm
- 🇷🇺 Русский
- aolko
- 🇹🇷 Türkçe
- Progresor
- Progesor

If you would like to contribute a translation, please create an issue or contact us on Discord. Include an email where we'll send an invite to our [POEditor](https://poeditor.com/) project.

Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Avalonia/Assets/hf-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
"config.json",
"model.safetensors"
],
"Subfolder": "ip_adapter_sd_image_encoder",
"Subfolder": "ip_adapter_sdxl_image_encoder",
"LicenseType": "Apache 2.0"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace StabilityMatrix.Avalonia.ViewModels.Base;
/// This includes a progress reporter, image output view model, and generation virtual methods.
/// </summary>
[SuppressMessage("ReSharper", "VirtualMemberNeverOverridden.Global")]
public abstract partial class InferenceGenerationViewModelBase : InferenceTabViewModelBase, IImageGalleryComponent
public abstract partial class InferenceGenerationViewModelBase
: InferenceTabViewModelBase,
IImageGalleryComponent
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

Expand Down Expand Up @@ -98,7 +100,15 @@ protected Task<FilePath> WriteOutputImageAsync(
var defaultOutputDir = settingsManager.ImagesInferenceDirectory;
defaultOutputDir.Create();

return WriteOutputImageAsync(imageStream, defaultOutputDir, args, batchNum, batchTotal, isGrid, fileExtension);
return WriteOutputImageAsync(
imageStream,
defaultOutputDir,
args,
batchNum,
batchTotal,
isGrid,
fileExtension
);
}

/// <summary>
Expand Down Expand Up @@ -130,7 +140,10 @@ protected async Task<FilePath> WriteOutputImageAsync(
)
{
// Fallback to default
Logger.Warn("Failed to parse format template: {FormatTemplate}, using default", formatTemplateStr);
Logger.Warn(
"Failed to parse format template: {FormatTemplate}, using default",
formatTemplateStr
);

format = FileNameFormat.Parse(FileNameFormat.DefaultTemplate, formatProvider);
}
Expand Down Expand Up @@ -303,10 +316,17 @@ 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.TryGetValue(args.OutputNodeNames[0], out var images)
|| images is not { Count: > 0 }
)
{
// No images match
notificationService.Show("No output", "Did not receive any output images", NotificationType.Warning);
notificationService.Show(
"No output",
"Did not receive any output images",
NotificationType.Warning
);
return;
}

Expand Down Expand Up @@ -339,7 +359,10 @@ await DialogHelper
/// <summary>
/// Handles image output metadata for generation runs
/// </summary>
private async Task ProcessOutputImages(IReadOnlyCollection<ComfyImage> images, ImageGenerationEventArgs args)
private async Task ProcessOutputImages(
IReadOnlyCollection<ComfyImage> images,
ImageGenerationEventArgs args
)
{
var client = args.Client;

Expand Down Expand Up @@ -397,36 +420,6 @@ private async Task ProcessOutputImages(IReadOnlyCollection<ComfyImage> images, I
outputImages.Add(new ImageSource(filePath));
EventManager.Instance.OnImageFileAdded(filePath);
}
else if (comfyImage.FileName.EndsWith(".webp"))
{
// Write using generated name
var webpFilePath = await WriteOutputImageAsync(
new MemoryStream(imageArray),
args,
i + 1,
images.Count,
fileExtension: Path.GetExtension(comfyImage.FileName).Replace(".", "")
);

// convert to gif
/*var inputStream = File.OpenRead(webpFilePath);
var gifFilePath = webpFilePath.ToString().Replace(".webp", ".gif");
var outputStream = File.OpenWrite(gifFilePath);
await GifConverter.ConvertAnimatedWebpToGifAsync(inputStream, outputStream);
await inputStream.DisposeAsync();
await outputStream.FlushAsync();
await outputStream.DisposeAsync();*/

// if (File.Exists(gifFilePath))
// {
// // delete webp
// File.Delete(webpFilePath);
// }

outputImages.Add(new ImageSource(webpFilePath));
EventManager.Instance.OnImageFileAdded(webpFilePath);
}
else
{
// Write using generated name
Expand Down Expand Up @@ -458,7 +451,11 @@ private async Task ProcessOutputImages(IReadOnlyCollection<ComfyImage> images, I
var gridBytesWithMetadata = PngDataHelper.AddMetadata(gridBytes, args.Parameters!, args.Project!);

// Save to disk
var gridPath = await WriteOutputImageAsync(new MemoryStream(gridBytesWithMetadata), args, isGrid: true);
var gridPath = await WriteOutputImageAsync(
new MemoryStream(gridBytesWithMetadata),
args,
isGrid: true
);

// Insert to start of images
var gridImage = new ImageSource(gridPath);
Expand Down Expand Up @@ -492,7 +489,10 @@ protected virtual Task GenerateImageImpl(GenerateOverrides overrides, Cancellati
/// <param name="options">Optional overrides (side buttons)</param>
/// <param name="cancellationToken">Cancellation token</param>
[RelayCommand(IncludeCancelCommand = true, FlowExceptionsToTaskScheduler = true)]
private async Task GenerateImage(GenerateFlags options = default, CancellationToken cancellationToken = default)
private async Task GenerateImage(
GenerateFlags options = default,
CancellationToken cancellationToken = default
)
{
var overrides = GenerateOverrides.FromFlags(options);

Expand Down Expand Up @@ -535,17 +535,15 @@ protected virtual void OnPreviewImageReceived(object? sender, ComfyWebSocketImag
/// </summary>
protected virtual void OnProgressUpdateReceived(object? sender, ComfyProgressUpdateEventArgs args)
{
Dispatcher
.UIThread
.Post(() =>
{
OutputProgress.Value = args.Value;
OutputProgress.Maximum = args.Maximum;
OutputProgress.IsIndeterminate = false;
Dispatcher.UIThread.Post(() =>
{
OutputProgress.Value = args.Value;
OutputProgress.Maximum = args.Maximum;
OutputProgress.IsIndeterminate = false;

OutputProgress.Text =
$"({args.Value} / {args.Maximum})" + (args.RunningNode != null ? $" {args.RunningNode}" : "");
});
OutputProgress.Text =
$"({args.Value} / {args.Maximum})" + (args.RunningNode != null ? $" {args.RunningNode}" : "");
});
}

private void AttachRunningNodeChangedHandler(ComfyTask comfyTask)
Expand All @@ -570,15 +568,13 @@ protected virtual void OnRunningNodeChanged(object? sender, string? nodeName)
return;
}

Dispatcher
.UIThread
.Post(() =>
{
OutputProgress.IsIndeterminate = true;
OutputProgress.Value = 100;
OutputProgress.Maximum = 100;
OutputProgress.Text = nodeName;
});
Dispatcher.UIThread.Post(() =>
{
OutputProgress.IsIndeterminate = true;
OutputProgress.Value = 100;
OutputProgress.Maximum = 100;
OutputProgress.Text = nodeName;
});
}

public class ImageGenerationEventArgs : EventArgs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
Expand All @@ -8,6 +10,8 @@
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Services;

namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
Expand Down Expand Up @@ -49,12 +53,12 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
[NotifyPropertyChangedFor(nameof(DisplayedPageNumber))]
private int selectedImageIndex;

[ObservableProperty]
private string importTooltip = string.Empty;

public int DisplayedPageNumber => SelectedImageIndex + 1;

public SelectModelVersionViewModel(
ISettingsManager settingsManager,
IDownloadService downloadService
)
public SelectModelVersionViewModel(ISettingsManager settingsManager, IDownloadService downloadService)
{
this.settingsManager = settingsManager;
this.downloadService = downloadService;
Expand All @@ -70,7 +74,9 @@ partial void OnSelectedVersionViewModelChanged(ModelVersionViewModel? value)
{
var nsfwEnabled = settingsManager.Settings.ModelBrowserNsfwEnabled;
var allImages = value
?.ModelVersion?.Images?.Where(img => nsfwEnabled || img.Nsfw == "None")
?.ModelVersion
?.Images
?.Where(img => nsfwEnabled || img.Nsfw == "None")
?.Select(x => new ImageSource(x.Url))
.ToList();

Expand All @@ -95,7 +101,22 @@ partial void OnSelectedVersionViewModelChanged(ModelVersionViewModel? value)

partial void OnSelectedFileChanged(CivitFileViewModel? value)
{
IsImportEnabled = value?.CivitFile != null;
var canImport = true;
if (settingsManager.IsLibraryDirSet)
{
var fileSizeBytes = value?.CivitFile.SizeKb * 1024;
var freeSizeBytes = SystemInfo.GetDiskFreeSpaceBytes(settingsManager.ModelsDirectory);
canImport = fileSizeBytes < freeSizeBytes;
ImportTooltip = canImport
? $"Free space after download: {Size.FormatBytes(Convert.ToUInt64(freeSizeBytes - fileSizeBytes))}"
: $"Not enough space on disk. Need {Size.FormatBytes(Convert.ToUInt64(fileSizeBytes))} but only have {Size.FormatBytes(Convert.ToUInt64(freeSizeBytes))}";
}
else
{
ImportTooltip = "Please set the library directory in settings";
}

IsImportEnabled = value?.CivitFile != null && canImport;
}

public void Cancel()
Expand Down
Loading

0 comments on commit 8165293

Please sign in to comment.