Browse Source

Add image metadata parsing internals, debug menu

pull/165/head
Ionite 1 year ago
parent
commit
384884e187
No known key found for this signature in database
  1. 44
      StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs
  2. 5
      StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj
  3. 22
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  4. 12
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml
  5. 1
      StabilityMatrix.Core/StabilityMatrix.Core.csproj

44
StabilityMatrix.Avalonia/Helpers/ImageMetadata.cs

@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using MetadataExtractor;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Models.FileInterfaces;
namespace StabilityMatrix.Avalonia.Helpers;
public class ImageMetadata
{
private IReadOnlyList<Directory>? Directories { get; set; }
public static ImageMetadata ParseFile(FilePath path)
{
return new ImageMetadata() { Directories = ImageMetadataReader.ReadMetadata(path) };
}
public string? GetComfyMetadata()
{
if (Directories is null)
{
return null;
}
// For Comfy, we want the PNG-tEXt directory
if (Directories.FirstOrDefault(d => d.Name == "PNG-tEXt") is not { } pngText)
{
return null;
}
// Expect the 'Textual Data' tag
if (
pngText.Tags.FirstOrDefault(tag => tag.Name == "Textual Data") is not { } textTag
|| textTag.Description is null
)
{
return null;
}
// Strip `prompt: ` and the rest of the description is json
return textTag.Description.StripStart("prompt:").TrimStart();
}
}

5
StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj

@ -29,14 +29,15 @@
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="Dock.Avalonia" Version="11.0.0" />
<PackageReference Include="Dock.Model.Avalonia" Version="11.0.0" />
<PackageReference Include="Dock.Avalonia" Version="11.0.0.1" />
<PackageReference Include="Dock.Model.Avalonia" Version="11.0.0.1" />
<PackageReference Include="FluentAvaloniaUI" Version="2.0.1" />
<PackageReference Include="DynamicData" Version="7.14.2" />
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.207" />
<PackageReference Include="FluentIcons.FluentAvalonia" Version="1.1.207" />
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.0" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />

22
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -729,6 +729,28 @@ public partial class SettingsViewModel : PageViewModelBase
notificationService.Show("Loaded completion file", "");
}
[RelayCommand]
private async Task DebugImageMetadata()
{
var provider = App.StorageProvider;
var files = await provider.OpenFilePickerAsync(new FilePickerOpenOptions());
if (files.Count == 0)
return;
var metadata = ImageMetadata.ParseFile(files[0].TryGetLocalPath()!);
var comfyJson = metadata.GetComfyMetadata();
if (comfyJson is null)
{
notificationService.Show("No Comfy metadata found", "");
return;
}
var dialog = DialogHelper.CreateJsonDialog(comfyJson);
await dialog.ShowAsync();
}
[RelayCommand]
private async Task DebugRefreshModelsIndex()
{

12
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -406,6 +406,18 @@
Content="Select images" />
</ui:SettingsExpanderItem.Footer>
</ui:SettingsExpanderItem>
<ui:SettingsExpanderItem
Margin="4,0,4,4"
Content="Image metadata parser"
IconSource="Flag">
<ui:SettingsExpanderItem.Footer>
<Button
Margin="0,8"
Command="{Binding DebugImageMetadataCommand}"
Content="Choose image" />
</ui:SettingsExpanderItem.Footer>
</ui:SettingsExpanderItem>
</ui:SettingsExpander>
</Grid>

1
StabilityMatrix.Core/StabilityMatrix.Core.csproj

@ -23,6 +23,7 @@
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.2.1" />
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="LiteDB.Async" Version="0.1.6" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="NLog" Version="5.2.2" />

Loading…
Cancel
Save