Skip to content

Commit

Permalink
Merge pull request LykosAI#458 from ionite34/checkpoint-updates-n-stuff
Browse files Browse the repository at this point in the history
add Find in Model Browser button on Checkpoints page context menu
  • Loading branch information
mohnjiles authored Jan 11, 2024
2 parents b85e444 + 20ff29d commit e071006
Show file tree
Hide file tree
Showing 18 changed files with 395 additions and 209 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
- Added base model filter to Checkpoints page
- Search box on Checkpoints page now searches tags and trigger words
- Added "Compatible Images" category when selecting images for Inference projects
- Added "Find in Model Browser" option to the right-click menu on the Checkpoints page
### Changed
- Removed "Failed to load image" notification when loading some images on the Checkpoints page
- Installed models will no longer be selectable on the Hugging Face tab of the model browser
Expand Down
1 change: 1 addition & 0 deletions StabilityMatrix.Avalonia/DesignData/DesignData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public static void Initialize()
PreviewImagePath =
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/"
+ "78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg",
UpdateAvailable = true,
ConnectedModel = new ConnectedModelInfo
{
VersionName = "Lightning Auroral",
Expand Down
5 changes: 5 additions & 0 deletions StabilityMatrix.Avalonia/DesignData/MockModelIndexService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public Task<bool> RemoveModelAsync(LocalModelFile model)
return Task.FromResult(false);
}

public Task CheckModelsForUpdates()
{
return Task.CompletedTask;
}

/// <inheritdoc />
public void BackgroundRefreshIndex() { }
}
9 changes: 9 additions & 0 deletions StabilityMatrix.Avalonia/Languages/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions StabilityMatrix.Avalonia/Languages/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -927,4 +927,7 @@
<data name="Label_VideoQuality" xml:space="preserve">
<value>Quality</value>
</data>
<data name="Label_FindInModelBrowser" xml:space="preserve">
<value>Find in Model Browser</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using LiteDB;
using LiteDB.Async;
using NLog;
using OneOf.Types;
using Refit;
using StabilityMatrix.Avalonia.Languages;
using StabilityMatrix.Avalonia.Services;
Expand Down Expand Up @@ -160,6 +161,17 @@ INotificationService notificationService
.Where(page => page <= TotalPages && page > 0)
.ObserveOn(SynchronizationContext.Current)
.Subscribe(_ => TrySearchAgain(false).SafeFireAndForget(), err => Logger.Error(err));

EventManager.Instance.NavigateAndFindCivitModelRequested += OnNavigateAndFindCivitModelRequested;
}

private void OnNavigateAndFindCivitModelRequested(object? sender, int e)
{
if (e <= 0)
return;

SearchQuery = $"$#{e}";
SearchModelsCommand.ExecuteAsync(null).SafeFireAndForget();
}

public override void OnLoaded()
Expand Down Expand Up @@ -399,6 +411,16 @@ private async Task SearchModels()
Page = CurrentPageNumber
};

if (SelectedModelType != CivitModelType.All)
{
modelRequest.Types = [SelectedModelType];
}

if (SelectedBaseModelType != "All")
{
modelRequest.BaseModel = SelectedBaseModelType;
}

if (SearchQuery.StartsWith("#"))
{
modelRequest.Tag = SearchQuery[1..];
Expand All @@ -407,19 +429,16 @@ private async Task SearchModels()
{
modelRequest.Username = SearchQuery[1..];
}
else
{
modelRequest.Query = SearchQuery;
}

if (SelectedModelType != CivitModelType.All)
else if (SearchQuery.StartsWith("$#"))
{
modelRequest.Types = [SelectedModelType];
modelRequest.Period = CivitPeriod.AllTime;
modelRequest.BaseModel = null;
modelRequest.Types = null;
modelRequest.CommaSeparatedModelIds = SearchQuery[2..];
}

if (SelectedBaseModelType != "All")
else
{
modelRequest.BaseModel = SelectedBaseModelType;
modelRequest.Query = SearchQuery;
}

if (SortMode == CivitSortMode.Installed)
Expand Down
37 changes: 28 additions & 9 deletions StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using System.Threading.Tasks;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.CheckpointBrowser;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using Symbol = FluentIcons.Common.Symbol;
using SymbolIconSource = FluentIcons.FluentAvalonia.SymbolIconSource;

namespace StabilityMatrix.Avalonia.ViewModels;

[View(typeof(CheckpointBrowserPage))]
[Singleton]
public partial class CheckpointBrowserViewModel(
CivitAiBrowserViewModel civitAiBrowserViewModel,
HuggingFacePageViewModel huggingFaceViewModel
) : PageViewModelBase
public partial class CheckpointBrowserViewModel : PageViewModelBase
{
public override string Title => "Model Browser";
public override IconSource IconSource => new SymbolIconSource { Symbol = Symbol.BrainCircuit, IsFilled = true };
public override IconSource IconSource =>
new SymbolIconSource { Symbol = Symbol.BrainCircuit, IsFilled = true };

public IReadOnlyList<TabItem> Pages { get; } =
new List<TabItem>(
public IReadOnlyList<TabItem> Pages { get; }

[ObservableProperty]
private TabItem? selectedPage;

/// <inheritdoc/>
public CheckpointBrowserViewModel(
CivitAiBrowserViewModel civitAiBrowserViewModel,
HuggingFacePageViewModel huggingFaceViewModel
)
{
Pages = new List<TabItem>(
new List<TabViewModelBase>([civitAiBrowserViewModel, huggingFaceViewModel]).Select(
vm => new TabItem { Header = vm.Header, Content = vm }
)
);
SelectedPage = Pages.FirstOrDefault();
EventManager.Instance.NavigateAndFindCivitModelRequested += OnNavigateAndFindCivitModelRequested;
}

private void OnNavigateAndFindCivitModelRequested(object? sender, int e)
{
SelectedPage = Pages.FirstOrDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public partial class CheckpointFile : ViewModelBase
[ObservableProperty]
private ProgressReport? progress;

[ObservableProperty]
private bool updateAvailable;

public string FileName => Path.GetFileName(FilePath);

public bool CanShowTriggerWords =>
Expand Down Expand Up @@ -212,6 +215,15 @@ private async Task RenameAsync()
}
}

[RelayCommand]
private void FindOnModelBrowser()
{
if (ConnectedModel?.ModelId == null)
return;

EventManager.Instance.OnNavigateAndFindCivitModelRequested(ConnectedModel.ModelId);
}

[RelayCommand]
private void OpenOnCivitAi()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -660,12 +659,10 @@ public void Index()
SubFoldersCache.EditDiff(updatedFolders, (a, b) => a.Title == b.Title);

// Index files
var files = GetCheckpointFiles();

Dispatcher.UIThread.Post(
() =>
{
var files = GetCheckpointFiles();
checkpointFilesCache.EditDiff(files, CheckpointFile.FilePathComparer);
},
() => checkpointFilesCache.EditDiff(files, CheckpointFile.FilePathComparer),
DispatcherPriority.Background
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
Expand Down Expand Up @@ -153,7 +152,6 @@ ModelFinder modelFinder
public override void OnLoaded()
{
base.OnLoaded();

var sw = Stopwatch.StartNew();

// Set UI states
Expand All @@ -173,7 +171,6 @@ public override void OnLoaded()

IsLoading = CheckpointFolders.Count == 0;
IsIndexing = CheckpointFolders.Count > 0;
// GetStuff();
IndexFolders();
IsLoading = false;
IsIndexing = false;
Expand Down
2 changes: 0 additions & 2 deletions StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using FluentAvalonia.UI.Controls;
using KGySoft.CoreLibraries;
using NLog;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Services;
Expand Down
3 changes: 2 additions & 1 deletion StabilityMatrix.Avalonia/Views/CheckpointBrowserPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
x:DataType="viewModels:CheckpointBrowserViewModel"
mc:Ignorable="d"
x:Class="StabilityMatrix.Avalonia.Views.CheckpointBrowserPage">
<TabControl ItemsSource="{Binding Pages}"/>
<TabControl ItemsSource="{Binding Pages}"
SelectedItem="{Binding SelectedPage}"/>
</controls:UserControlBase>
Loading

0 comments on commit e071006

Please sign in to comment.