Browse Source

Add generation parameters to image index db entry

pull/165/head
Ionite 1 year ago
parent
commit
88325cdbf0
No known key found for this signature in database
  1. 1
      StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs
  2. 1
      StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs
  3. 25
      StabilityMatrix.Core/Helper/ImageMetadata.cs
  4. 5
      StabilityMatrix.Core/Models/Database/LocalImageFile.cs
  5. 3
      StabilityMatrix.Core/Models/GenerationParameters.cs
  6. 7
      StabilityMatrix.Core/Services/ImageIndexService.cs

1
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;

1
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;

25
StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs → 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<Directory>? 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<Tag>? 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()

5
StabilityMatrix.Core/Models/Database/LocalImageFile.cs

@ -28,6 +28,11 @@ public class LocalImageFile
/// </summary>
public DateTimeOffset LastModifiedAt { get; set; }
/// <summary>
/// Generation parameters metadata of the file.
/// </summary>
public GenerationParameters? GenerationParameters { get; set; }
/// <summary>
/// File name of the relative path.
/// </summary>

3
StabilityMatrix.Avalonia/Models/Inference/GenerationParameters.cs → 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

7
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

Loading…
Cancel
Save