Browse Source

Set default preview for A1111 installs to TAESD & added Reset Checkpoint Cache button to settings page

pull/55/head
JT 1 year ago
parent
commit
23940a5e2b
  1. 3
      StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
  2. 10
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  3. 16
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml
  4. 19
      StabilityMatrix.Core/Models/Packages/A3WebUI.cs
  5. 43
      StabilityMatrix.Core/Services/SettingsManager.cs

3
StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls.Primitives;
using CommunityToolkit.Mvvm.ComponentModel;
using FluentAvalonia.UI.Controls;
@ -62,7 +63,7 @@ public partial class MainWindowViewModel : ViewModelBase
}
// Index checkpoints if we dont have
settingsManager.IndexCheckpoints();
Task.Run(() => settingsManager.IndexCheckpoints()).SafeFireAndForget();
if (!settingsManager.Settings.InstalledPackages.Any())
{

10
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -118,6 +118,14 @@ public partial class SettingsViewModel : PageViewModelBase
settingsManager.Transaction(s => s.RemoveFolderLinksOnShutdown = value);
}
public async Task ResetCheckpointCache()
{
settingsManager.Transaction(s => s.InstalledModelHashes = new HashSet<string>());
await Task.Run(() => settingsManager.IndexCheckpoints());
notificationService.Show("Checkpoint cache reset", "The checkpoint cache has been reset.",
NotificationType.Success);
}
#region Package Environment
[RelayCommand]
@ -186,8 +194,6 @@ public partial class SettingsViewModel : PageViewModelBase
}
#endregion
#region System

16
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -41,7 +41,7 @@
<!-- TODO: Text2Image host port settings -->
<!-- Checkpoints Manager Options -->
<Grid RowDefinitions="auto,*">
<Grid RowDefinitions="auto,*,Auto">
<TextBlock
FontWeight="Medium"
Text="Checkpoint Manager"
@ -51,12 +51,24 @@
IconSource="Folder"
Header="Remove shared checkpoints directory symbolic links on shutdown"
Description="Select this option if you're having problems moving Stability Matrix to another drive"
Margin="8,0">
Margin="8,8">
<ui:SettingsExpander.Footer>
<CheckBox Margin="8"
IsChecked="{Binding RemoveSymlinksOnShutdown}"/>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<ui:SettingsExpander
Grid.Row="2"
IconSource="Refresh"
Header="Reset Checkpoints Cache"
Description="Rebuilds the installed checkpoints cache. Use if checkpoints are incorrectly labeled in the Model Browser."
Margin="8,0">
<ui:SettingsExpander.Footer>
<Button Margin="8"
Command="{Binding ResetCheckpointCache}"
Content="Reset Checkpoints Cache"/>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
</Grid>
<!-- Environment Options -->

19
StabilityMatrix.Core/Models/Packages/A3WebUI.cs

@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using NLog;
using StabilityMatrix.Core.Helper;
@ -123,7 +124,7 @@ public class A3WebUI : BaseGitPackage
{
await UnzipPackage(progress);
progress?.Report(new ProgressReport(-1, "Setting up venv", isIndeterminate: true));
progress?.Report(new ProgressReport(-1f, "Setting up venv", isIndeterminate: true));
// Setup venv
await using var venvRunner = new PyVenvRunner(Path.Combine(InstallLocation, "venv"));
venvRunner.WorkingDirectory = InstallLocation;
@ -136,7 +137,7 @@ public class A3WebUI : BaseGitPackage
var gpus = HardwareHelper.IterGpuInfo().ToList();
if (gpus.Any(g => g.IsNvidia))
{
progress?.Report(new ProgressReport(-1, "Installing PyTorch for CUDA", isIndeterminate: true));
progress?.Report(new ProgressReport(-1f, "Installing PyTorch for CUDA", isIndeterminate: true));
Logger.Info("Starting torch install (CUDA)...");
await venvRunner.PipInstall(PyVenvRunner.TorchPipInstallArgsCuda, OnConsoleOutput)
@ -147,17 +148,25 @@ public class A3WebUI : BaseGitPackage
}
else
{
progress?.Report(new ProgressReport(-1, "Installing PyTorch for CPU", isIndeterminate: true));
progress?.Report(new ProgressReport(-1f, "Installing PyTorch for CPU", isIndeterminate: true));
Logger.Info("Starting torch install (CPU)...");
await venvRunner.PipInstall(PyVenvRunner.TorchPipInstallArgsCpu, OnConsoleOutput).ConfigureAwait(false);
}
// Install requirements file
progress?.Report(new ProgressReport(-1, "Installing Package Requirements", isIndeterminate: true));
progress?.Report(new ProgressReport(-1f, "Installing Package Requirements", isIndeterminate: true));
Logger.Info("Installing requirements_versions.txt");
await venvRunner.PipInstall($"-r requirements_versions.txt", OnConsoleOutput).ConfigureAwait(false);
progress?.Report(new ProgressReport(1, "Installing Package Requirements", isIndeterminate: false));
progress?.Report(new ProgressReport(1f, "Installing Package Requirements", isIndeterminate: false));
progress?.Report(new ProgressReport(-1f, "Updating configuration", isIndeterminate: true));
// Create and add {"show_progress_type": "TAESD"} to config.json
var configPath = Path.Combine(InstallLocation, "config.json");
var config = new JsonObject {{"show_progress_type", "TAESD"}};
await File.WriteAllTextAsync(configPath, config.ToString()).ConfigureAwait(false);
progress?.Report(new ProgressReport(1f, "Install complete", isIndeterminate: false));
}
public override async Task RunPackage(string installedPackagePath, string command, string arguments)

43
StabilityMatrix.Core/Services/SettingsManager.cs

@ -436,34 +436,31 @@ public class SettingsManager : ISettingsManager
if (Settings.InstalledModelHashes.Any())
return;
Task.Run(() =>
var sw = new Stopwatch();
sw.Start();
var modelHashes = new HashSet<string>();
var sharedModelDirectory = Path.Combine(LibraryDir, "Models");
if (!Directory.Exists(sharedModelDirectory)) return;
var connectedModelJsons = Directory.GetFiles(sharedModelDirectory, "*.cm-info.json",
SearchOption.AllDirectories);
foreach (var jsonFile in connectedModelJsons)
{
var sw = new Stopwatch();
sw.Start();
var json = File.ReadAllText(jsonFile);
var connectedModel = JsonSerializer.Deserialize<ConnectedModelInfo>(json);
var modelHashes = new HashSet<string>();
var sharedModelDirectory = Path.Combine(LibraryDir, "Models");
if (!Directory.Exists(sharedModelDirectory)) return;
var connectedModelJsons = Directory.GetFiles(sharedModelDirectory, "*.cm-info.json",
SearchOption.AllDirectories);
foreach (var jsonFile in connectedModelJsons)
if (connectedModel?.Hashes.BLAKE3 != null)
{
var json = File.ReadAllText(jsonFile);
var connectedModel = JsonSerializer.Deserialize<ConnectedModelInfo>(json);
if (connectedModel?.Hashes.BLAKE3 != null)
{
modelHashes.Add(connectedModel.Hashes.BLAKE3);
}
modelHashes.Add(connectedModel.Hashes.BLAKE3);
}
}
Transaction(s => s.InstalledModelHashes = modelHashes);
sw.Stop();
Logger.Info($"Indexed {modelHashes.Count} checkpoints in {sw.ElapsedMilliseconds}ms");
}).SafeFireAndForget();
Transaction(s => s.InstalledModelHashes = modelHashes);
sw.Stop();
Logger.Info($"Indexed {modelHashes.Count} checkpoints in {sw.ElapsedMilliseconds}ms");
}
/// <summary>

Loading…
Cancel
Save