Browse Source

Merge pull request #365 from ionite34/trigger-words

Added the download & display of trigger words for models
pull/324/head
JT 1 year ago committed by GitHub
parent
commit
8e450345e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      CHANGELOG.md
  2. 3
      StabilityMatrix.Avalonia/DesignData/DesignData.cs
  3. 18
      StabilityMatrix.Avalonia/Languages/Resources.Designer.cs
  4. 6
      StabilityMatrix.Avalonia/Languages/Resources.resx
  5. 16
      StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs
  6. 10
      StabilityMatrix.Avalonia/Views/CheckpointBrowserPage.axaml
  7. 136
      StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml
  8. 25
      StabilityMatrix.Core/Models/ConnectedModelInfo.cs

20
CHANGELOG.md

@ -5,6 +5,21 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
## v2.7.0-dev.3
### Added
#### Model Browser
- Right clicking anywhere on the model card will open the same menu as the three-dots button
- New model downloads will save trigger words in metadata, if available
#### Checkpoints Page
- Added "Copy Trigger Words" option to the three-dots menu on the Checkpoints page (when data is available)
- Added trigger words on checkpoint card and tooltip
### Changed
#### Model Browser
- Improved number formatting with K/M suffixes for download and favorite counts
- Animated zoom effect on hovering over model images
#### Checkpoints Page
- Rearranged top row layout to use CommandBar
## v2.7.0-dev.2
### Added
#### General
@ -38,11 +53,6 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
## v2.6.3
### Fixed
- Fixed InvalidOperationException during prerequisite installs on certain platforms where process name and duration reporting are not supported
## v2.7.0-dev.3
## Changed
#### Model Browser
- Improved number formatting with K/M suffixes for download and favorite counts
- Animated zoom effect on hovering over model images
## v2.6.2
### Changed

3
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -206,7 +206,8 @@ public static class DesignData
Format = CivitModelFormat.SafeTensor,
Fp = CivitModelFpType.fp16,
Size = CivitModelSize.pruned,
}
},
TrainedWords = ["aurora", "lightning"]
}
},
new()

18
StabilityMatrix.Avalonia/Languages/Resources.Designer.cs generated

@ -167,6 +167,15 @@ namespace StabilityMatrix.Avalonia.Languages {
}
}
/// <summary>
/// Looks up a localized string similar to Copy Trigger Words.
/// </summary>
public static string Action_CopyTriggerWords {
get {
return ResourceManager.GetString("Action_CopyTriggerWords", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete.
/// </summary>
@ -1796,6 +1805,15 @@ namespace StabilityMatrix.Avalonia.Languages {
}
}
/// <summary>
/// Looks up a localized string similar to Trigger words:.
/// </summary>
public static string Label_TriggerWords {
get {
return ResourceManager.GetString("Label_TriggerWords", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unexpected error occurred.
/// </summary>

6
StabilityMatrix.Avalonia/Languages/Resources.resx

@ -804,4 +804,10 @@
<data name="TextTemplate_LastChecked" xml:space="preserve">
<value>Last checked: {0}</value>
</data>
<data name="Action_CopyTriggerWords" xml:space="preserve">
<value>Copy Trigger Words</value>
</data>
<data name="Label_TriggerWords" xml:space="preserve">
<value>Trigger words:</value>
</data>
</root>

16
StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs

@ -60,6 +60,9 @@ public partial class CheckpointFile : ViewModelBase
public string FileName => Path.GetFileName(FilePath);
public bool CanShowTriggerWords =>
ConnectedModel != null && !string.IsNullOrWhiteSpace(ConnectedModel.TrainedWordsString);
public ObservableCollection<string> Badges { get; set; } = new();
public static readonly string[] SupportedCheckpointExtensions =
@ -215,6 +218,19 @@ public partial class CheckpointFile : ViewModelBase
ProcessRunner.OpenUrl($"https://civitai.com/models/{ConnectedModel.ModelId}");
}
[RelayCommand]
private Task CopyTriggerWords()
{
if (ConnectedModel == null)
return Task.CompletedTask;
var words = ConnectedModel.TrainedWordsString;
if (string.IsNullOrWhiteSpace(words))
return Task.CompletedTask;
return App.Clipboard.SetTextAsync(words);
}
/// <summary>
/// Indexes directory and yields all checkpoint files.
/// First we match all files with supported extensions.

10
StabilityMatrix.Avalonia/Views/CheckpointBrowserPage.axaml

@ -78,6 +78,16 @@
Margin="8"
ClipToBounds="True"
CornerRadius="8">
<Border.ContextFlyout>
<MenuFlyout>
<MenuItem Header="{x:Static lang:Resources.Action_OpenOnCivitAi}"
Command="{Binding OpenModelCommand}">
<MenuItem.Icon>
<ui:SymbolIcon Symbol="Open" />
</MenuItem.Icon>
</MenuItem>
</MenuFlyout>
</Border.ContextFlyout>
<Button
Name="ModelCard"
Classes="transparent-full"

136
StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml

@ -9,10 +9,11 @@
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:checkpointManager="clr-namespace:StabilityMatrix.Avalonia.ViewModels.CheckpointManager"
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
xmlns:avalonia="https://github.com/projektanker/icons.avalonia"
d:DataContext="{x:Static mocks:DesignData.CheckpointsPageViewModel}"
x:CompileBindings="True"
x:DataType="vm:CheckpointsPageViewModel"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650"
x:Class="StabilityMatrix.Avalonia.Views.CheckpointsPage">
<controls:UserControlBase.Resources>
@ -66,12 +67,17 @@
<ui:MenuFlyoutItem Command="{Binding OpenOnCivitAiCommand}"
Text="{x:Static lang:Resources.Action_OpenOnCivitAi}" IconSource="Link"
IsVisible="{Binding IsConnectedModel}" />
<ui:MenuFlyoutItem Command="{Binding CopyTriggerWordsCommand}"
IsVisible="{Binding CanShowTriggerWords}"
Text="{x:Static lang:Resources.Action_CopyTriggerWords}"
IconSource="Copy" />
</ui:FAMenuFlyout>
</controls:Card.ContextFlyout>
<Grid>
<!-- Main contents, hidden when IsLoading is true -->
<StackPanel MinHeight="70">
<Grid ColumnDefinitions="*, Auto" RowDefinitions="Auto,*,Auto" IsVisible="{Binding !IsLoading}">
<Grid ColumnDefinitions="*, Auto" RowDefinitions="Auto,*,Auto,Auto"
IsVisible="{Binding !IsLoading}">
<StackPanel
Grid.ColumnSpan="2"
HorizontalAlignment="Left"
@ -106,6 +112,17 @@
Source="{Binding PreviewImagePath}"
Stretch="Uniform"
IsVisible="{Binding IsConnectedModel}" />
<TextBlock
FontSize="13"
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
HorizontalAlignment="Left"
Margin="0,0,0,4"
TextWrapping="WrapWithOverflow"
IsVisible="{Binding CanShowTriggerWords}">
<Run Text="{x:Static lang:Resources.Label_TriggerWords}" />
<Run
Text="{Binding ConnectedModel.TrainedWordsString, FallbackValue=''}" />
</TextBlock>
</StackPanel>
</ToolTip.Tip>
<TextBlock
@ -179,7 +196,7 @@
Grid.Column="0"
Grid.Row="2"
IsEnabled="True"
Margin="4,4"
Margin="0,4"
Text="{Binding FileName}"
TextTrimming="CharacterEllipsis"
ToolTip.Tip="{Binding FileName}"
@ -196,6 +213,20 @@
<UniformGridLayout />
</ItemsRepeater.Layout>
</ItemsRepeater>
<TextBlock Grid.Row="3" Grid.Column="0"
Grid.ColumnSpan="2"
FontSize="11"
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Margin="0,4,0,0"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
ToolTip.Tip="{Binding ConnectedModel.TrainedWordsString, FallbackValue=''}"
IsVisible="{Binding CanShowTriggerWords}">
<Run Text="{x:Static lang:Resources.Label_TriggerWords}" />
<Run Text="{Binding ConnectedModel.TrainedWordsString, FallbackValue=''}" />
</TextBlock>
</Grid>
</StackPanel>
@ -241,7 +272,8 @@
<ui:MenuFlyoutSeparator />
<ui:MenuFlyoutSubItem Text="{x:Static lang:Resources.Action_New}" IconSource="Add">
<ui:MenuFlyoutSubItem.Items>
<ui:MenuFlyoutItem Text="{x:Static lang:Resources.Label_Folder}" IconSource="OpenFolder"
<ui:MenuFlyoutItem Text="{x:Static lang:Resources.Label_Folder}"
IconSource="OpenFolder"
Command="{Binding CreateSubFolderCommand}" />
</ui:MenuFlyoutSubItem.Items>
</ui:MenuFlyoutSubItem>
@ -378,29 +410,8 @@
<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,*" Margin="4, 0"
x:Name="ParentGrid">
<!-- Top settings bar -->
<StackPanel Grid.Column="0" Grid.Row="0">
<ToggleSwitch
OffContent="{x:Static lang:Resources.Label_ImportAsConnected}"
OnContent="{x:Static lang:Resources.Label_ImportAsConnected}"
IsChecked="{Binding IsImportAsConnected}"
Margin="24,4,24,-4"
ToolTip.Tip="{x:Static lang:Resources.Label_ImportAsConnectedExplanation}" />
<ToggleSwitch
OffContent="{x:Static lang:Resources.Label_ShowModelImages}"
OnContent="{x:Static lang:Resources.Label_ShowModelImages}"
IsChecked="{Binding ShowConnectedModelImages}"
Margin="24,-4,24,4" />
</StackPanel>
<StackPanel
Grid.Column="1"
Grid.Row="0"
Spacing="8"
HorizontalAlignment="Right"
Margin="16,0"
Orientation="Horizontal">
<TextBox Margin="8, 16"
<StackPanel Orientation="Horizontal">
<TextBox Margin="16, 16, 8, 16"
Watermark="{x:Static lang:Resources.Action_Search}"
Height="16"
MinWidth="220"
@ -421,22 +432,9 @@
</Grid>
</TextBox.InnerRightContent>
</TextBox>
<controls:ProgressRing
Width="16"
Height="16"
BorderThickness="4"
IsIndeterminate="True"
IsVisible="{Binding IsIndexing}"/>
<TextBlock Text="{x:Static lang:Resources.Label_Indexing}" FontSize="11"
VerticalAlignment="Center"
IsVisible="{Binding IsIndexing}"/>
<Button
Command="{Binding OpenModelsFolderCommand}">
<TextBlock Text="{x:Static lang:Resources.Label_ModelsFolder}"/>
</Button>
<DropDownButton
Content="{x:Static lang:Resources.Label_Categories}"
Margin="8"
Margin="8,0"
VerticalAlignment="Center"
HorizontalAlignment="Right">
<DropDownButton.Flyout>
@ -453,6 +451,62 @@
</DropDownButton.Flyout>
</DropDownButton>
</StackPanel>
<ui:CommandBar
Grid.Row="0"
Grid.Column="1"
x:Name="CommandBar"
Margin="8,0,0,0"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
DefaultLabelPosition="Right">
<ui:CommandBar.PrimaryCommands>
<ui:CommandBarButton
IconSource="OpenFolder"
VerticalAlignment="Center"
Label="{x:Static lang:Resources.Label_ModelsFolder}"
Command="{Binding OpenModelsFolderCommand}" />
<ui:CommandBarButton
IconSource="Refresh"
VerticalAlignment="Center"
Command="{Binding OnLoaded}"
Label="{x:Static lang:Resources.Action_Refresh}" />
<ui:CommandBarToggleButton
IconSource="Image"
Label="{x:Static lang:Resources.Label_ShowModelImages}"
IsChecked="{Binding ShowConnectedModelImages, Mode=TwoWay}">
</ui:CommandBarToggleButton>
</ui:CommandBar.PrimaryCommands>
<ui:CommandBar.SecondaryCommands>
<ui:CommandBarToggleButton
IconSource="Cloud"
Label="{x:Static lang:Resources.Label_ImportAsConnected}"
IsChecked="{Binding IsImportAsConnected, Mode=TwoWay}">
</ui:CommandBarToggleButton>
</ui:CommandBar.SecondaryCommands>
</ui:CommandBar>
<StackPanel
IsVisible="False"
Grid.Column="1"
Grid.Row="0"
Spacing="8"
HorizontalAlignment="Right"
Margin="16,0"
Orientation="Horizontal">
<controls:ProgressRing
Width="16"
Height="16"
BorderThickness="4"
IsIndeterminate="True"
IsVisible="{Binding IsIndexing}" />
<TextBlock Text="{x:Static lang:Resources.Label_Indexing}" FontSize="11"
VerticalAlignment="Center"
IsVisible="{Binding IsIndexing}" />
</StackPanel>
<!-- Main view with model cards -->
<ScrollViewer

25
StabilityMatrix.Core/Models/ConnectedModelInfo.cs

@ -22,16 +22,20 @@ public class ConnectedModelInfo
public CivitFileMetadata FileMetadata { get; set; }
public DateTimeOffset ImportedAt { get; set; }
public CivitFileHashes Hashes { get; set; }
public string[]? TrainedWords { get; set; }
// User settings
public string? UserTitle { get; set; }
public string? ThumbnailImageUrl { get; set; }
public ConnectedModelInfo()
{
}
public ConnectedModelInfo() { }
public ConnectedModelInfo(CivitModel civitModel, CivitModelVersion civitModelVersion, CivitFile civitFile, DateTimeOffset importedAt)
public ConnectedModelInfo(
CivitModel civitModel,
CivitModelVersion civitModelVersion,
CivitFile civitFile,
DateTimeOffset importedAt
)
{
ModelId = civitModel.Id;
ModelName = civitModel.Name;
@ -46,11 +50,18 @@ public class ConnectedModelInfo
BaseModel = civitModelVersion.BaseModel;
FileMetadata = civitFile.Metadata;
Hashes = civitFile.Hashes;
TrainedWords = civitModelVersion.TrainedWords;
}
public static ConnectedModelInfo? FromJson(string json)
{
return JsonSerializer.Deserialize<ConnectedModelInfo>(json, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull } );
return JsonSerializer.Deserialize<ConnectedModelInfo>(
json,
new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
}
);
}
/// <summary>
@ -65,4 +76,8 @@ public class ConnectedModelInfo
var json = JsonSerializer.Serialize(this);
await File.WriteAllTextAsync(Path.Combine(directoryPath, name), json);
}
[JsonIgnore]
public string TrainedWordsString =>
TrainedWords != null ? string.Join(", ", TrainedWords) : string.Empty;
}

Loading…
Cancel
Save