|
|
@ -28,6 +28,8 @@ using StabilityMatrix.Core.Models.Api.Comfy; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.Nodes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.Nodes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.WebSocketData; |
|
|
|
using StabilityMatrix.Core.Models.Api.Comfy.WebSocketData; |
|
|
|
|
|
|
|
using StabilityMatrix.Core.Models.Database; |
|
|
|
|
|
|
|
using StabilityMatrix.Core.Models.FileInterfaces; |
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
using InferenceTextToImageView = StabilityMatrix.Avalonia.Views.Inference.InferenceTextToImageView; |
|
|
|
using InferenceTextToImageView = StabilityMatrix.Avalonia.Views.Inference.InferenceTextToImageView; |
|
|
|
|
|
|
|
|
|
|
@ -43,6 +45,7 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
private readonly INotificationService notificationService; |
|
|
|
private readonly INotificationService notificationService; |
|
|
|
private readonly ServiceManager<ViewModelBase> vmFactory; |
|
|
|
private readonly ServiceManager<ViewModelBase> vmFactory; |
|
|
|
private readonly IModelIndexService modelIndexService; |
|
|
|
private readonly IModelIndexService modelIndexService; |
|
|
|
|
|
|
|
private readonly IImageIndexService imageIndexService; |
|
|
|
|
|
|
|
|
|
|
|
[JsonIgnore] |
|
|
|
[JsonIgnore] |
|
|
|
public IInferenceClientManager ClientManager { get; } |
|
|
|
public IInferenceClientManager ClientManager { get; } |
|
|
@ -103,12 +106,14 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
INotificationService notificationService, |
|
|
|
INotificationService notificationService, |
|
|
|
IInferenceClientManager inferenceClientManager, |
|
|
|
IInferenceClientManager inferenceClientManager, |
|
|
|
ServiceManager<ViewModelBase> vmFactory, |
|
|
|
ServiceManager<ViewModelBase> vmFactory, |
|
|
|
IModelIndexService modelIndexService |
|
|
|
IModelIndexService modelIndexService, |
|
|
|
|
|
|
|
IImageIndexService imageIndexService |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.notificationService = notificationService; |
|
|
|
this.notificationService = notificationService; |
|
|
|
this.vmFactory = vmFactory; |
|
|
|
this.vmFactory = vmFactory; |
|
|
|
this.modelIndexService = modelIndexService; |
|
|
|
this.modelIndexService = modelIndexService; |
|
|
|
|
|
|
|
this.imageIndexService = imageIndexService; |
|
|
|
ClientManager = inferenceClientManager; |
|
|
|
ClientManager = inferenceClientManager; |
|
|
|
|
|
|
|
|
|
|
|
// Get sub view models from service manager |
|
|
|
// Get sub view models from service manager |
|
|
@ -416,7 +421,23 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
notificationService.Show("No output", "Did not receive any output images"); |
|
|
|
notificationService.Show("No output", "Did not receive any output images"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Disconnect progress handler |
|
|
|
|
|
|
|
OutputProgress.Value = 0; |
|
|
|
|
|
|
|
OutputProgress.Text = ""; |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.PreviewImage?.Dispose(); |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.PreviewImage = null; |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.IsPreviewOverlayEnabled = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promptTask?.Dispose(); |
|
|
|
|
|
|
|
client.PreviewImageReceived -= OnPreviewImageReceived; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task ProcessOutputs(IReadOnlyList<ComfyImage> images) |
|
|
|
|
|
|
|
{ |
|
|
|
List<ImageSource> outputImages; |
|
|
|
List<ImageSource> outputImages; |
|
|
|
// Use local file path if available, otherwise use remote URL |
|
|
|
// Use local file path if available, otherwise use remote URL |
|
|
|
if (client.OutputImagesDir is { } outputPath) |
|
|
|
if (client.OutputImagesDir is { } outputPath) |
|
|
@ -425,21 +446,30 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
foreach (var image in images) |
|
|
|
foreach (var image in images) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var filePath = image.ToFilePath(outputPath); |
|
|
|
var filePath = image.ToFilePath(outputPath); |
|
|
|
var fileStream = new BinaryReader(filePath.Info.OpenRead()); |
|
|
|
|
|
|
|
var bytes = fileStream.ReadBytes((int)filePath.Info.Length); |
|
|
|
|
|
|
|
var bytesWithMetadata = PngDataHelper.AddMetadata( |
|
|
|
var bytesWithMetadata = PngDataHelper.AddMetadata( |
|
|
|
bytes, |
|
|
|
await filePath.ReadAllBytesAsync(), |
|
|
|
generationInfo, |
|
|
|
generationInfo, |
|
|
|
smproj |
|
|
|
smproj |
|
|
|
); |
|
|
|
); |
|
|
|
fileStream.Close(); |
|
|
|
|
|
|
|
fileStream.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await using var outputStream = filePath.Info.OpenWrite(); |
|
|
|
/*await using (var readStream = filePath.Info.OpenWrite()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
using (var reader = new BinaryReader(readStream)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await using (var outputStream = filePath.Info.OpenWrite()) |
|
|
|
|
|
|
|
{ |
|
|
|
await outputStream.WriteAsync(bytesWithMetadata); |
|
|
|
await outputStream.WriteAsync(bytesWithMetadata); |
|
|
|
await outputStream.FlushAsync(); |
|
|
|
await outputStream.FlushAsync(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
outputImages.Add(new ImageSource(filePath)); |
|
|
|
outputImages.Add(new ImageSource(filePath)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imageIndexService.OnImageAdded(filePath); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -478,6 +508,8 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
// Preload |
|
|
|
// Preload |
|
|
|
await gridImage.GetBitmapAsync(); |
|
|
|
await gridImage.GetBitmapAsync(); |
|
|
|
ImageGalleryCardViewModel.ImageSources.Add(gridImage); |
|
|
|
ImageGalleryCardViewModel.ImageSources.Add(gridImage); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imageIndexService.OnImageAdded(gridPath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add rest of images |
|
|
|
// Add rest of images |
|
|
@ -488,19 +520,6 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
ImageGalleryCardViewModel.ImageSources.Add(img); |
|
|
|
ImageGalleryCardViewModel.ImageSources.Add(img); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
finally |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Disconnect progress handler |
|
|
|
|
|
|
|
OutputProgress.Value = 0; |
|
|
|
|
|
|
|
OutputProgress.Text = ""; |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.PreviewImage?.Dispose(); |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.PreviewImage = null; |
|
|
|
|
|
|
|
ImageGalleryCardViewModel.IsPreviewOverlayEnabled = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promptTask?.Dispose(); |
|
|
|
|
|
|
|
client.PreviewImageReceived -= OnPreviewImageReceived; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand(IncludeCancelCommand = true, FlowExceptionsToTaskScheduler = true)] |
|
|
|
[RelayCommand(IncludeCancelCommand = true, FlowExceptionsToTaskScheduler = true)] |
|
|
|
private async Task GenerateImage( |
|
|
|
private async Task GenerateImage( |
|
|
@ -517,7 +536,6 @@ public partial class InferenceTextToImageViewModel : InferenceTabViewModelBase |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await GenerateImageImpl(overrides, cancellationToken); |
|
|
|
await GenerateImageImpl(overrides, cancellationToken); |
|
|
|
await ImageFolderCardViewModel.OnLoadedAsync(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (OperationCanceledException e) |
|
|
|
catch (OperationCanceledException e) |
|
|
|
{ |
|
|
|
{ |
|
|
|