Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
Margin="0,0,0,0"
Padding="6,0,6,0"
Classes="Circle LightBlue"
Content="{Binding Local.ConnectedModelInfo.BaseModel}"
Content="{Binding Local.DisplayBaseModel}"
FontSize="10"
FontWeight="SemiBold"
Theme="{StaticResource TagLabel}" />
Expand Down Expand Up @@ -517,7 +517,7 @@
Margin="0,0,0,0"
Padding="6,0,6,0"
Classes="Circle LightBlue"
Content="{Binding Local.ConnectedModelInfo.BaseModel}"
Content="{Binding Local.DisplayBaseModel}"
FontSize="10"
FontWeight="SemiBold"
Theme="{StaticResource TagLabel}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public partial class CheckpointFileViewModel : SelectableViewModelBase
private readonly IServiceManager<ViewModelBase> vmFactory;
private readonly ILogger logger;

public bool CanShowTriggerWords => CheckpointFile.ConnectedModelInfo?.TrainedWords?.Length > 0;
public string BaseModelName => CheckpointFile.ConnectedModelInfo?.BaseModel ?? string.Empty;
public bool CanShowTriggerWords => CheckpointFile.DisplayTrainedWords?.Length > 0;
public string BaseModelName => CheckpointFile.DisplayBaseModel ?? string.Empty;
public CivitModelType ModelType => CheckpointFile.ConnectedModelInfo?.ModelType ?? CivitModelType.Unknown;
public bool HasEarlyAccessUpdateOnly => CheckpointFile.HasEarlyAccessUpdateOnly;
public bool HasStandardUpdate => CheckpointFile.HasUpdate && !CheckpointFile.HasEarlyAccessUpdateOnly;
Expand Down Expand Up @@ -115,10 +115,7 @@ LocalModelFile checkpointFile
[RelayCommand]
private Task CopyTriggerWords()
{
if (!CheckpointFile.HasConnectedModel)
return Task.CompletedTask;

var words = CheckpointFile.ConnectedModelInfo.TrainedWordsString;
var words = CheckpointFile.DisplayTrainedWordsString;
return string.IsNullOrWhiteSpace(words) ? Task.CompletedTask : App.Clipboard.SetTextAsync(words);
}

Expand Down Expand Up @@ -203,7 +200,7 @@ is not IMetadataImportService importService
CheckpointFile.ConnectedModelInfo = cmInfo;

var uri =
CheckpointFile.GetPreviewImageFullPath(settingsManager.ModelsDirectory)
CheckpointFile.GetDisplayPreviewImageFullPath(settingsManager.ModelsDirectory)
?? cmInfo.ThumbnailImageUrl;
if (string.IsNullOrWhiteSpace(uri))
{
Expand Down Expand Up @@ -638,7 +635,7 @@ private void UpdateImage()
else
{
var previewPath = settingsManager.IsLibraryDirSet
? CheckpointFile.GetPreviewImageFullPath(settingsManager.ModelsDirectory)
? CheckpointFile.GetDisplayPreviewImageFullPath(settingsManager.ModelsDirectory)
?? CheckpointFile.ConnectedModelInfo?.ThumbnailImageUrl
: null;

Expand Down
28 changes: 7 additions & 21 deletions StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ protected override async Task OnInitialLoadedAsync()
|| file.DisplayModelName.Contains(SearchQuery, StringComparison.OrdinalIgnoreCase)
|| file.DisplayModelVersion.Contains(SearchQuery, StringComparison.OrdinalIgnoreCase)
|| (
file.ConnectedModelInfo?.TrainedWordsString.Contains(
file.DisplayTrainedWordsString.Contains(
SearchQuery,
StringComparison.OrdinalIgnoreCase
) ?? false
)
)
)
)
Expand Down Expand Up @@ -281,12 +281,8 @@ or nameof(SortConnectedModelsFirst)
case CheckpointSortMode.BaseModel:
comparer =
SelectedSortDirection == ListSortDirection.Ascending
? comparer.ThenByAscending(vm =>
vm.CheckpointFile.ConnectedModelInfo?.BaseModel
)
: comparer.ThenByDescending(vm =>
vm.CheckpointFile.ConnectedModelInfo?.BaseModel
);
? comparer.ThenByAscending(vm => vm.CheckpointFile.DisplayBaseModel)
: comparer.ThenByDescending(vm => vm.CheckpointFile.DisplayBaseModel);

comparer = comparer.ThenByAscending(vm => vm.CheckpointFile.DisplayModelName);
break;
Expand Down Expand Up @@ -1299,10 +1295,8 @@ private bool FilterModels(LocalModelFile file)
return false;

if (SelectedCategory?.Path is null || SelectedCategory?.Path == settingsManager.ModelsDirectory)
return file.HasConnectedModel
? SelectedBaseModels.Count == 0
|| SelectedBaseModels.Contains(file.ConnectedModelInfo.BaseModel ?? "Other")
: SelectedBaseModels.Count == 0 || SelectedBaseModels.Contains("Other");
return SelectedBaseModels.Count == 0
|| SelectedBaseModels.Contains(file.DisplayBaseModel ?? "Other");

var categoryRelativePath = SelectedCategory
?.Path.Replace(settingsManager.ModelsDirectory, string.Empty)
Expand All @@ -1311,15 +1305,7 @@ private bool FilterModels(LocalModelFile file)
if (categoryRelativePath == null || folderPath == null)
return false;

if (
(
file.HasConnectedModel
? SelectedBaseModels.Count == 0
|| SelectedBaseModels.Contains(file.ConnectedModelInfo?.BaseModel ?? "Other")
: SelectedBaseModels.Count == 0 || SelectedBaseModels.Contains("Other")
)
is false
)
if (SelectedBaseModels.Count != 0 && !SelectedBaseModels.Contains(file.DisplayBaseModel ?? "Other"))
return false;

// If not showing nested models, just check if the file is directly in this folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ IServiceManager<ViewModelBase> vmFactory
public IObservableCollection<HybridModelFile> LoraModels { get; } =
new ObservableCollectionExtended<HybridModelFile>();

public string TriggerWords =>
SelectedModel?.Local?.ConnectedModelInfo?.TrainedWordsString ?? string.Empty;
public string TriggerWords => SelectedModel?.Local?.DisplayTrainedWordsString ?? string.Empty;
public bool ShowTriggerWords => !string.IsNullOrWhiteSpace(TriggerWords);

public IInferenceClientManager ClientManager { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ SelectedWorkflowProfile is InferenceWorkflowProfile.Auto
{
// Respect explicit metadata: an SDXL-tagged checkpoint that merely contains
// "anima" or "flux2" in its filename is not a misplaced standalone model.
var taggedBase = local.ConnectedModelInfo?.BaseModel;
var taggedBase = local.DisplayBaseModel;
if (!string.IsNullOrWhiteSpace(taggedBase) && IsKnownCheckpointBaseModelTag(taggedBase))
return null;

Expand Down Expand Up @@ -901,7 +901,7 @@ private static InferenceWorkflowProfile InferWorkflowProfile(HybridModelFile? mo
if (!isUnetModel)
return InferenceWorkflowProfile.DefaultCheckpoint;

var baseModel = model?.Local?.ConnectedModelInfo?.BaseModel;
var baseModel = model?.Local?.DisplayBaseModel;

if (!string.IsNullOrWhiteSpace(baseModel))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private async Task AmplifyPrompt()

var negativePrompt = GetNegativePrompt();
var selectedModel = tabContext.SelectedModel;
var modelTags = selectedModel?.Local?.ConnectedModelInfo?.BaseModel?.ToLower() switch
var modelTags = selectedModel?.Local?.DisplayBaseModel?.ToLower() switch
{
{ } baseModel when baseModel.Contains("flux") => new List<ModelTags> { ModelTags.Flux },
{ } baseModel when baseModel.Contains("sdxl") => [ModelTags.Sdxl],
Expand Down
15 changes: 11 additions & 4 deletions StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,21 @@
<LayoutTransformControl.LayoutTransform>
<ScaleTransform ScaleX="{Binding $parent[scroll:BetterScrollViewer].((viewModels:CheckpointsPageViewModel)DataContext).ModelCardBottomResizeFactor, FallbackValue=1, TargetNullValue=1}" ScaleY="{Binding $parent[scroll:BetterScrollViewer].((viewModels:CheckpointsPageViewModel)DataContext).ModelCardBottomResizeFactor, FallbackValue=1, TargetNullValue=1}" />
</LayoutTransformControl.LayoutTransform>
<WrapPanel IsVisible="{Binding CheckpointFile.HasConnectedModel}" Orientation="Horizontal">
<WrapPanel Orientation="Horizontal">
<WrapPanel.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.Or}">
<CompiledBinding Path="CheckpointFile.HasConnectedModel" />
<CompiledBinding Converter="{x:Static StringConverters.IsNotNullOrEmpty}" Path="BaseModelName" />
</MultiBinding>
</WrapPanel.IsVisible>
<controls:Card
Height="24"
Margin="8,8,0,0"
Padding="4"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Classes="info">
Classes="info"
IsVisible="{Binding CheckpointFile.HasConnectedModel}">

<TextBlock
HorizontalAlignment="Center"
Expand Down Expand Up @@ -728,9 +735,9 @@
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
IsVisible="{Binding CanShowTriggerWords}"
TextWrapping="NoWrap"
ToolTip.Tip="{Binding CheckpointFile.ConnectedModelInfo.TrainedWordsString}">
ToolTip.Tip="{Binding CheckpointFile.DisplayTrainedWordsString}">
<Run Text="Trigger words:" />
<Run Text="{Binding CheckpointFile.ConnectedModelInfo.TrainedWordsString}" />
<Run Text="{Binding CheckpointFile.DisplayTrainedWordsString}" />
</TextBlock>
</StackPanel>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@
MinHeight="0"
Padding="8,2"
Classes="Circle LightBlue"
Content="{Binding Local.ConnectedModelInfo.BaseModel, FallbackValue=''}"
Content="{Binding Local.DisplayBaseModel, FallbackValue=''}"
FontSize="11"
FontWeight="SemiBold"
IsVisible="{Binding Local.ConnectedModelInfo.BaseModel, Converter={x:Static StringConverters.IsNotNullOrEmpty}, FallbackValue=False}"
IsVisible="{Binding Local.DisplayBaseModel, Converter={x:Static StringConverters.IsNotNullOrEmpty}, FallbackValue=False}"
Theme="{StaticResource TagLabel}" />
</StackPanel>
</sg:SpacedGrid>
Expand Down Expand Up @@ -486,10 +486,10 @@
MinHeight="0"
Padding="8,2"
Classes="Circle LightBlue"
Content="{Binding Local.ConnectedModelInfo.BaseModel, FallbackValue=''}"
Content="{Binding Local.DisplayBaseModel, FallbackValue=''}"
FontSize="11"
FontWeight="SemiBold"
IsVisible="{Binding Local.ConnectedModelInfo.BaseModel, Converter={x:Static StringConverters.IsNotNullOrEmpty}, FallbackValue=False}"
IsVisible="{Binding Local.DisplayBaseModel, Converter={x:Static StringConverters.IsNotNullOrEmpty}, FallbackValue=False}"
Theme="{StaticResource TagLabel}" />
</StackPanel>

Expand Down
16 changes: 5 additions & 11 deletions StabilityMatrix.Core/Helper/ModelCompatChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ public class ModelCompatChecker

public bool? IsLoraCompatibleWithBaseModel(HybridModelFile? lora, HybridModelFile? baseModel)
{
// Require connected info for both
// Require a known base model for both
if (
lora?.Local?.ConnectedModelInfo is not { } loraInfo
|| baseModel?.Local?.ConnectedModelInfo is not { } baseModelInfo
lora?.Local?.DisplayBaseModel is not { } loraBaseModel
|| !baseModelNamesToTypes.TryGetValue(loraBaseModel, out var loraBaseModelType)
)
return null;

if (
loraInfo.BaseModel is null
|| !baseModelNamesToTypes.TryGetValue(loraInfo.BaseModel, out var loraBaseModelType)
)
return null;

if (
baseModelInfo.BaseModel is null
|| !baseModelNamesToTypes.TryGetValue(baseModelInfo.BaseModel, out var baseModelType)
baseModel?.Local?.DisplayBaseModel is not { } baseModelName
|| !baseModelNamesToTypes.TryGetValue(baseModelName, out var baseModelType)
)
return null;

Expand Down
3 changes: 2 additions & 1 deletion StabilityMatrix.Core/Helper/ModelFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ModelFinder(ILiteDbContext liteDbContext, ICivitApi civitApi)
return new ModelSearchResult(model, version, file);
}

// Finds a model using Civit API using file hash
// Finds a model using Civit API using file hash (BLAKE3 or SHA256)
public async Task<ModelSearchResult?> RemoteFindModel(string hashBlake3)
{
Logger.Info("Searching Civit API for model version using hash {Hash}", hashBlake3);
Expand All @@ -58,6 +58,7 @@ public ModelFinder(ILiteDbContext liteDbContext, ICivitApi civitApi)

var file = versionResponse.Files.FirstOrDefault(file =>
hashBlake3.Equals(file.Hashes.BLAKE3, StringComparison.OrdinalIgnoreCase)
|| hashBlake3.Equals(file.Hashes.SHA256, StringComparison.OrdinalIgnoreCase)
);

// Archived models do not have files
Expand Down
45 changes: 44 additions & 1 deletion StabilityMatrix.Core/Models/Database/LocalModelFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public override int GetHashCode()
/// </summary>
public string? PreviewImageFullPath { get; set; }

/// <summary>
/// Optional full path to a cached copy of the cover image embedded in the model file.
/// Only used when there is no preview image file.
/// </summary>
public string? EmbeddedPreviewImageFullPath { get; set; }

/// <summary>
/// Optional base model declared in the model file's metadata.
/// Only used when <see cref="ConnectedModelInfo"/> has no base model.
/// </summary>
public string? EmbeddedBaseModel { get; set; }

/// <summary>
/// Optional trigger words declared in the model file's metadata.
/// Only used when <see cref="ConnectedModelInfo"/> has no trigger words.
/// </summary>
public string[]? EmbeddedTrainedWords { get; set; }

/// <summary>
/// Optional full path to the model's configuration (.yaml) file.
/// </summary>
Expand Down Expand Up @@ -142,12 +160,28 @@ public override int GetHashCode()

[BsonIgnore]
public string? PreviewImageFullPathGlobal =>
PreviewImageFullPath ?? GetPreviewImageFullPath(GlobalConfig.ModelsDir);
PreviewImageFullPath ?? GetDisplayPreviewImageFullPath(GlobalConfig.ModelsDir);

[BsonIgnore]
public Uri? PreviewImageUriGlobal =>
PreviewImageFullPathGlobal == null ? null : new Uri(PreviewImageFullPathGlobal);

[BsonIgnore]
public string? DisplayBaseModel =>
string.IsNullOrWhiteSpace(ConnectedModelInfo?.BaseModel)
? EmbeddedBaseModel
: ConnectedModelInfo.BaseModel;

[BsonIgnore]
public string[]? DisplayTrainedWords =>
ConnectedModelInfo?.TrainedWords is { Length: > 0 } trainedWords
? trainedWords
: EmbeddedTrainedWords;

[BsonIgnore]
public string DisplayTrainedWordsString =>
DisplayTrainedWords is { } trainedWords ? string.Join(", ", trainedWords) : string.Empty;

[BsonIgnore]
public string DisplayModelName => ConnectedModelInfo?.ModelName ?? FileNameWithoutExtension;

Expand Down Expand Up @@ -196,6 +230,15 @@ public string GetFullPath(string rootModelDirectory)
: Path.Combine(rootModelDirectory, PreviewImageRelativePath);
}

/// <summary>
/// Gets the image to show for this model: the preview image file if there is one,
/// otherwise the cover image embedded in the model file.
/// </summary>
public string? GetDisplayPreviewImageFullPath(string rootModelDirectory)
{
return GetPreviewImageFullPath(rootModelDirectory) ?? EmbeddedPreviewImageFullPath;
}

public string GetConnectedModelInfoFullPath(string rootModelDirectory)
{
var modelNameNoExt = Path.GetFileNameWithoutExtension(RelativePath);
Expand Down
Loading
Loading