diff --git a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs index 9f67ab69..8d253518 100644 --- a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs +++ b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs @@ -5,6 +5,7 @@ using System.Text.Json; using Force.Crc32; using StabilityMatrix.Avalonia.Models; using StabilityMatrix.Avalonia.Models.Inference; +using StabilityMatrix.Core.Models; namespace StabilityMatrix.Avalonia.Helpers; diff --git a/StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs index 32982b67..86b5411e 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs @@ -24,6 +24,7 @@ using StabilityMatrix.Avalonia.ViewModels.Base; using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Inference; +using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models.Api.Comfy; using StabilityMatrix.Core.Models.Api.Comfy.Nodes; using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; diff --git a/StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs b/StabilityMatrix.Core/Helper/ImageMetadata.cs similarity index 72% rename from StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs rename to StabilityMatrix.Core/Helper/ImageMetadata.cs index 568177c1..dcda0d4d 100644 --- a/StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs +++ b/StabilityMatrix.Core/Helper/ImageMetadata.cs @@ -1,33 +1,28 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -using System.Text.RegularExpressions; +using System.Text.Json; using MetadataExtractor; -using StabilityMatrix.Avalonia.Models.Inference; using StabilityMatrix.Core.Extensions; +using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models.FileInterfaces; +using Directory = MetadataExtractor.Directory; -namespace StabilityMatrix.Avalonia.Helpers; +namespace StabilityMatrix.Core.Helper; -public partial class ImageMetadata +public class ImageMetadata { private IReadOnlyList? Directories { get; set; } public static ImageMetadata ParseFile(FilePath path) { - return new ImageMetadata() { Directories = ImageMetadataReader.ReadMetadata(path) }; + return new ImageMetadata { Directories = ImageMetadataReader.ReadMetadata(path) }; } public IEnumerable? GetTextualData() { // Get the PNG-tEXt directory - if (Directories?.FirstOrDefault(d => d.Name == "PNG-tEXt") is not { } pngText) - { - return null; - } - - // Expect the 'Textual Data' tag - return pngText.Tags.Where(tag => tag.Name == "Textual Data"); + return Directories? + .Where(d => d.Name == "PNG-tEXt") + .SelectMany(d => d.Tags) + .Where(t => t.Name == "Textual Data"); } public GenerationParameters? GetGenerationParameters() diff --git a/StabilityMatrix.Core/Models/Database/LocalImageFile.cs b/StabilityMatrix.Core/Models/Database/LocalImageFile.cs index 8480c3a9..6f7fb536 100644 --- a/StabilityMatrix.Core/Models/Database/LocalImageFile.cs +++ b/StabilityMatrix.Core/Models/Database/LocalImageFile.cs @@ -28,6 +28,11 @@ public class LocalImageFile /// public DateTimeOffset LastModifiedAt { get; set; } + /// + /// Generation parameters metadata of the file. + /// + public GenerationParameters? GenerationParameters { get; set; } + /// /// File name of the relative path. /// diff --git a/StabilityMatrix.Avalonia/Models/Inference/GenerationParameters.cs b/StabilityMatrix.Core/Models/GenerationParameters.cs similarity index 97% rename from StabilityMatrix.Avalonia/Models/Inference/GenerationParameters.cs rename to StabilityMatrix.Core/Models/GenerationParameters.cs index 846af61d..086aa272 100644 --- a/StabilityMatrix.Avalonia/Models/Inference/GenerationParameters.cs +++ b/StabilityMatrix.Core/Models/GenerationParameters.cs @@ -1,9 +1,8 @@ using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Text.Json.Serialization; using System.Text.RegularExpressions; -namespace StabilityMatrix.Avalonia.Models.Inference; +namespace StabilityMatrix.Core.Models; [JsonSerializable(typeof(GenerationParameters))] public partial class GenerationParameters diff --git a/StabilityMatrix.Core/Services/ImageIndexService.cs b/StabilityMatrix.Core/Services/ImageIndexService.cs index 655488e5..adae0beb 100644 --- a/StabilityMatrix.Core/Services/ImageIndexService.cs +++ b/StabilityMatrix.Core/Services/ImageIndexService.cs @@ -2,6 +2,7 @@ using AsyncAwaitBestPractices; using Microsoft.Extensions.Logging; using StabilityMatrix.Core.Database; +using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Models.Database; using StabilityMatrix.Core.Models.FileInterfaces; @@ -77,12 +78,16 @@ public class ImageIndexService : IImageIndexService const LocalImageFileType imageType = LocalImageFileType.Inference | LocalImageFileType.TextToImage; + // Get metadata + var metadata = ImageMetadata.ParseFile(file); + var localImage = new LocalImageFile { RelativePath = relativePath, ImageType = imageType, CreatedAt = file.Info.CreationTimeUtc, - LastModifiedAt = file.Info.LastWriteTimeUtc + LastModifiedAt = file.Info.LastWriteTimeUtc, + GenerationParameters = metadata.GetGenerationParameters() }; // Insert into database