-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add safetensor metadata parsing and display
- Loading branch information
Showing
12 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
StabilityMatrix.Avalonia/ViewModels/Dialogs/SafetensorMetadataViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Injectio.Attributes; | ||
using StabilityMatrix.Avalonia.ViewModels.Base; | ||
using StabilityMatrix.Avalonia.Views.Dialogs; | ||
using StabilityMatrix.Core.Attributes; | ||
using StabilityMatrix.Core.Models; | ||
|
||
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; | ||
|
||
[View(typeof(SafetensorMetadataDialog))] | ||
[ManagedService] | ||
[RegisterSingleton<SafetensorMetadataViewModel>] | ||
public partial class SafetensorMetadataViewModel : ContentDialogViewModelBase | ||
{ | ||
[ObservableProperty] | ||
private string? modelName; | ||
|
||
[ObservableProperty] | ||
private SafetensorMetadata metadata; | ||
|
||
[RelayCommand] | ||
public void CopyTagToClipboard(string tag) | ||
{ | ||
App.Clipboard?.SetTextAsync(tag); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
StabilityMatrix.Avalonia/Views/Dialogs/SafetensorMetadataDialog.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<controls:UserControlBase | ||
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.SafetensorMetadataDialog" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs" | ||
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" | ||
xmlns:models="clr-namespace:StabilityMatrix.Core.Models;assembly=StabilityMatrix.Core" | ||
xmlns:panels="using:Avalonia.Labs.Panels" | ||
xmlns:ui="using:FluentAvalonia.UI.Controls" | ||
d:DataContext="{x:Static mocks:DesignData.SafetensorMetadataViewModel}" | ||
d:DesignHeight="550" | ||
d:DesignWidth="700" | ||
x:DataType="dialogs:SafetensorMetadataViewModel" | ||
mc:Ignorable="d"> | ||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto"> | ||
<TextBlock | ||
Margin="8" | ||
HorizontalAlignment="Center" | ||
FontSize="24" | ||
FontWeight="SemiBold" | ||
Text="Safetensor Metadata" /> | ||
<TextBlock | ||
Grid.Row="1" | ||
Margin="8" | ||
HorizontalAlignment="Center" | ||
FontSize="16" | ||
FontWeight="SemiBold" | ||
Text="{Binding ModelName}" /> | ||
|
||
<!-- List of tags --> | ||
<TextBlock | ||
Grid.Row="2" | ||
Margin="8" | ||
HorizontalAlignment="Left" | ||
FontSize="16" | ||
FontWeight="SemiBold" | ||
IsVisible="{Binding Metadata.TagFrequency, Converter={x:Static ObjectConverters.IsNotNull}}" | ||
Text="Trained Tags" /> | ||
<ItemsControl | ||
Grid.Row="3" | ||
Margin="8" | ||
IsVisible="{Binding Metadata.TagFrequency, Converter={x:Static ObjectConverters.IsNotNull}}" | ||
ItemsSource="{Binding Metadata.TagFrequency}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Button | ||
Command="{Binding $parent[ItemsControl].((dialogs:SafetensorMetadataViewModel)DataContext).CopyTagToClipboardCommand}" | ||
CommandParameter="{Binding Name}" | ||
Cursor="Hand"> | ||
<StackPanel Orientation="Horizontal"> | ||
<TextBlock FontWeight="SemiBold" Text="{Binding Name}" /> | ||
<TextBlock Margin="5,0,0,0" Text="{Binding Frequency}" /> | ||
</StackPanel> | ||
</Button> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<panels:FlexPanel | ||
ColumnSpacing="5" | ||
RowSpacing="5" | ||
Wrap="Wrap" /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
</ItemsControl> | ||
|
||
<!-- All other metadata --> | ||
<TextBlock | ||
Grid.Row="4" | ||
Margin="8" | ||
HorizontalAlignment="Left" | ||
FontSize="16" | ||
FontWeight="SemiBold" | ||
Text="Other Metadata" /> | ||
|
||
<TextBlock | ||
Grid.Row="5" | ||
Margin="8" | ||
FontSize="16" | ||
FontStyle="Italic" | ||
IsVisible="{Binding !Metadata.OtherMetadata.Count}" | ||
Text="No Metadata" /> | ||
<ItemsControl | ||
Grid.Row="5" | ||
Margin="8" | ||
ItemsSource="{Binding Metadata.OtherMetadata}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<StackPanel Margin="5" Orientation="Vertical"> | ||
<TextBlock FontWeight="SemiBold" Text="{Binding Name}" /> | ||
<TextBlock Text="{Binding Value}" /> | ||
</StackPanel> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</Grid> | ||
</controls:UserControlBase> |
19 changes: 19 additions & 0 deletions
19
StabilityMatrix.Avalonia/Views/Dialogs/SafetensorMetadataDialog.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Injectio.Attributes; | ||
|
||
namespace StabilityMatrix.Avalonia.Views.Dialogs; | ||
|
||
[RegisterTransient<SafetensorMetadataDialog>] | ||
public partial class SafetensorMetadataDialog : UserControl | ||
{ | ||
public SafetensorMetadataDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.