Ionite
1 year ago
committed by
GitHub
115 changed files with 6773 additions and 3421 deletions
@ -1,3 +1,5 @@
|
||||
namespace StabilityMatrix.Avalonia.Diagnostics.LogViewer.Core.ViewModels; |
||||
|
||||
public class ViewModel : ObservableObject { /* skip */ } |
||||
public class ViewModel |
||||
: ObservableObject { /* skip */ |
||||
} |
||||
|
@ -0,0 +1,11 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Base; |
||||
|
||||
public partial class ConsoleProgressViewModel : ProgressViewModel |
||||
{ |
||||
public ConsoleViewModel Console { get; } = new(); |
||||
|
||||
[ObservableProperty] |
||||
private bool closeWhenFinished; |
||||
} |
@ -0,0 +1,26 @@
|
||||
using System; |
||||
using FluentAvalonia.UI.Controls; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Base; |
||||
|
||||
public class ContentDialogProgressViewModelBase : ConsoleProgressViewModel |
||||
{ |
||||
public event EventHandler<ContentDialogResult>? PrimaryButtonClick; |
||||
public event EventHandler<ContentDialogResult>? SecondaryButtonClick; |
||||
public event EventHandler<ContentDialogResult>? CloseButtonClick; |
||||
|
||||
public virtual void OnPrimaryButtonClick() |
||||
{ |
||||
PrimaryButtonClick?.Invoke(this, ContentDialogResult.Primary); |
||||
} |
||||
|
||||
public virtual void OnSecondaryButtonClick() |
||||
{ |
||||
SecondaryButtonClick?.Invoke(this, ContentDialogResult.Secondary); |
||||
} |
||||
|
||||
public virtual void OnCloseButtonClick() |
||||
{ |
||||
CloseButtonClick?.Invoke(this, ContentDialogResult.None); |
||||
} |
||||
} |
@ -1,8 +1,7 @@
|
||||
using System; |
||||
using FluentAvalonia.UI.Controls; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; |
||||
namespace StabilityMatrix.Avalonia.ViewModels.Base; |
||||
|
||||
public class ContentDialogViewModelBase : ViewModelBase |
||||
{ |
@ -0,0 +1,78 @@
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using Avalonia.Threading; |
||||
using FluentAvalonia.UI.Controls; |
||||
using StabilityMatrix.Avalonia.Controls; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Avalonia.Views.Dialogs; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.PackageModification; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Progress; |
||||
|
||||
public class PackageInstallProgressItemViewModel : ProgressItemViewModelBase |
||||
{ |
||||
private readonly IPackageModificationRunner packageModificationRunner; |
||||
private BetterContentDialog? dialog; |
||||
|
||||
public PackageInstallProgressItemViewModel(IPackageModificationRunner packageModificationRunner) |
||||
{ |
||||
this.packageModificationRunner = packageModificationRunner; |
||||
Id = packageModificationRunner.Id; |
||||
Name = packageModificationRunner.CurrentStep?.ProgressTitle; |
||||
Progress.Value = packageModificationRunner.CurrentProgress.Percentage; |
||||
Progress.Text = packageModificationRunner.ConsoleOutput.LastOrDefault(); |
||||
Progress.IsIndeterminate = packageModificationRunner.CurrentProgress.IsIndeterminate; |
||||
|
||||
Progress.Console.StartUpdates(); |
||||
|
||||
Progress.Console.Post( |
||||
string.Join(Environment.NewLine, packageModificationRunner.ConsoleOutput) |
||||
); |
||||
|
||||
packageModificationRunner.ProgressChanged += PackageModificationRunnerOnProgressChanged; |
||||
} |
||||
|
||||
private void PackageModificationRunnerOnProgressChanged(object? sender, ProgressReport e) |
||||
{ |
||||
Progress.Value = e.Percentage; |
||||
Progress.Description = e.Message; |
||||
Progress.IsIndeterminate = e.IsIndeterminate; |
||||
Progress.Text = packageModificationRunner.CurrentStep?.ProgressTitle; |
||||
Name = packageModificationRunner.CurrentStep?.ProgressTitle; |
||||
|
||||
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Contains("Downloading...")) |
||||
return; |
||||
|
||||
Progress.Console.PostLine(e.Message); |
||||
EventManager.Instance.OnScrollToBottomRequested(); |
||||
|
||||
if ( |
||||
e is { Message: not null, Percentage: >= 100 } |
||||
&& e.Message.Contains("Package Install Complete") |
||||
&& Progress.CloseWhenFinished |
||||
) |
||||
{ |
||||
Dispatcher.UIThread.Post(() => dialog?.Hide()); |
||||
} |
||||
} |
||||
|
||||
public async Task ShowProgressDialog() |
||||
{ |
||||
Progress.CloseWhenFinished = true; |
||||
dialog = new BetterContentDialog |
||||
{ |
||||
MaxDialogWidth = 900, |
||||
MinDialogWidth = 900, |
||||
DefaultButton = ContentDialogButton.Close, |
||||
IsPrimaryButtonEnabled = false, |
||||
IsSecondaryButtonEnabled = false, |
||||
IsFooterVisible = false, |
||||
Content = new PackageModificationDialog { DataContext = Progress } |
||||
}; |
||||
EventManager.Instance.OnToggleProgressFlyout(); |
||||
await dialog.ShowAsync(); |
||||
} |
||||
} |
@ -1,10 +1,8 @@
|
||||
using System; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
namespace StabilityMatrix.Avalonia.ViewModels.Progress; |
||||
|
||||
public class ProgressItemViewModel : ProgressItemViewModelBase |
||||
{ |
@ -0,0 +1,57 @@
|
||||
<controls:UserControlBase xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls" |
||||
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs" |
||||
xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit" |
||||
xmlns:base="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Base" |
||||
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
x:DataType="base:ContentDialogProgressViewModelBase" |
||||
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.PackageModificationDialog"> |
||||
<Grid Margin="8" RowDefinitions="Auto, Auto, Auto, *, Auto, Auto"> |
||||
<TextBlock Grid.Row="0" Text="{Binding Text}" |
||||
FontSize="16" |
||||
Margin="4" |
||||
TextWrapping="WrapWithOverflow" |
||||
TextAlignment="Center" |
||||
HorizontalAlignment="Stretch"/> |
||||
|
||||
<TextBlock Grid.Row="1" Text="{Binding Description}" |
||||
Margin="4" |
||||
TextWrapping="WrapWithOverflow" |
||||
TextAlignment="Center" |
||||
IsVisible="{Binding !#Expander.IsExpanded}"/> |
||||
|
||||
<ProgressBar Grid.Row="2" Value="{Binding Value}" |
||||
Margin="8" |
||||
IsIndeterminate="{Binding IsIndeterminate}"/> |
||||
|
||||
<Expander Grid.Row="3" |
||||
Margin="8" |
||||
Header="More Details" x:Name="Expander"> |
||||
<avaloniaEdit:TextEditor |
||||
x:Name="Console" |
||||
Margin="8" |
||||
MaxHeight="400" |
||||
DataContext="{Binding Console}" |
||||
Document="{Binding Document}" |
||||
FontFamily="Cascadia Code,Consolas,Menlo,Monospace" |
||||
IsReadOnly="True" |
||||
LineNumbersForeground="DarkSlateGray" |
||||
ShowLineNumbers="True" |
||||
VerticalScrollBarVisibility="Auto" |
||||
WordWrap="True" /> |
||||
</Expander> |
||||
|
||||
<CheckBox Grid.Row="4" IsChecked="{Binding CloseWhenFinished}" |
||||
HorizontalAlignment="Center" |
||||
Margin="4" Content="{x:Static lang:Resources.Label_CloseDialogWhenFinished}"/> |
||||
|
||||
<Button Grid.Row="5" Content="{x:Static lang:Resources.Action_Close}" |
||||
FontSize="20" |
||||
HorizontalAlignment="Center" |
||||
Command="{Binding OnCloseButtonClick}"/> |
||||
</Grid> |
||||
</controls:UserControlBase> |
@ -0,0 +1,51 @@
|
||||
using System; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Media; |
||||
using Avalonia.Threading; |
||||
using AvaloniaEdit; |
||||
using AvaloniaEdit.TextMate; |
||||
using StabilityMatrix.Avalonia.Controls; |
||||
using StabilityMatrix.Core.Helper; |
||||
using TextMateSharp.Grammars; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Views.Dialogs; |
||||
|
||||
public partial class PackageModificationDialog : UserControlBase |
||||
{ |
||||
public PackageModificationDialog() |
||||
{ |
||||
InitializeComponent(); |
||||
|
||||
var editor = this.FindControl<TextEditor>("Console"); |
||||
if (editor is not null) |
||||
{ |
||||
var options = new RegistryOptions(ThemeName.DarkPlus); |
||||
|
||||
// Config hyperlinks |
||||
editor.TextArea.Options.EnableHyperlinks = true; |
||||
editor.TextArea.Options.RequireControlModifierForHyperlinkClick = false; |
||||
editor.TextArea.TextView.LinkTextForegroundBrush = Brushes.Coral; |
||||
|
||||
var textMate = editor.InstallTextMate(options); |
||||
var scope = options.GetScopeByLanguageId("log"); |
||||
|
||||
if (scope is null) |
||||
throw new InvalidOperationException("Scope is null"); |
||||
|
||||
textMate.SetGrammar(scope); |
||||
textMate.SetTheme(options.LoadTheme(ThemeName.DarkPlus)); |
||||
} |
||||
|
||||
EventManager.Instance.ScrollToBottomRequested += (_, _) => |
||||
{ |
||||
Dispatcher.UIThread.Invoke(() => |
||||
{ |
||||
var editor = this.FindControl<TextEditor>("Console"); |
||||
if (editor?.Document == null) |
||||
return; |
||||
var line = Math.Max(editor.Document.LineCount - 1, 1); |
||||
editor.ScrollToLine(line); |
||||
}); |
||||
}; |
||||
} |
||||
} |
@ -1,6 +1,11 @@
|
||||
namespace StabilityMatrix.Core.Models.Database; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Core.Models.Database; |
||||
|
||||
public class GitCommit |
||||
{ |
||||
public string? Sha { get; set; } |
||||
|
||||
[JsonIgnore] |
||||
public string ShortSha => string.IsNullOrWhiteSpace(Sha) ? string.Empty : Sha[..7]; |
||||
} |
||||
|
@ -0,0 +1,8 @@
|
||||
namespace StabilityMatrix.Core.Models; |
||||
|
||||
public class DownloadPackageVersionOptions |
||||
{ |
||||
public string BranchName { get; set; } |
||||
public string CommitHash { get; set; } |
||||
public string VersionTag { get; set; } |
||||
} |
@ -0,0 +1,23 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Core.Models; |
||||
|
||||
public class InstalledPackageVersion |
||||
{ |
||||
public string? InstalledReleaseVersion { get; set; } |
||||
public string? InstalledBranch { get; set; } |
||||
public string? InstalledCommitSha { get; set; } |
||||
|
||||
[JsonIgnore] |
||||
public bool IsReleaseMode => string.IsNullOrWhiteSpace(InstalledBranch); |
||||
|
||||
[JsonIgnore] |
||||
public string DisplayVersion => |
||||
( |
||||
IsReleaseMode |
||||
? InstalledReleaseVersion |
||||
: string.IsNullOrWhiteSpace(InstalledCommitSha) |
||||
? InstalledBranch |
||||
: $"{InstalledBranch}@{InstalledCommitSha[..7]}" |
||||
) ?? string.Empty; |
||||
} |
@ -0,0 +1,33 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class AddInstalledPackageStep : IPackageStep |
||||
{ |
||||
private readonly ISettingsManager settingsManager; |
||||
private readonly InstalledPackage newInstalledPackage; |
||||
|
||||
public AddInstalledPackageStep( |
||||
ISettingsManager settingsManager, |
||||
InstalledPackage newInstalledPackage |
||||
) |
||||
{ |
||||
this.settingsManager = settingsManager; |
||||
this.newInstalledPackage = newInstalledPackage; |
||||
} |
||||
|
||||
public async Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
if (!string.IsNullOrWhiteSpace(newInstalledPackage.DisplayName)) |
||||
{ |
||||
settingsManager.PackageInstallsInProgress.Remove(newInstalledPackage.DisplayName); |
||||
} |
||||
|
||||
await using var transaction = settingsManager.BeginTransaction(); |
||||
transaction.Settings.InstalledPackages.Add(newInstalledPackage); |
||||
transaction.Settings.ActiveInstalledPackageId = newInstalledPackage.Id; |
||||
} |
||||
|
||||
public string ProgressTitle => $"{newInstalledPackage.DisplayName} Installed"; |
||||
} |
@ -0,0 +1,27 @@
|
||||
using StabilityMatrix.Core.Models.Packages; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class DownloadPackageVersionStep : IPackageStep |
||||
{ |
||||
private readonly BasePackage package; |
||||
private readonly string installPath; |
||||
private readonly DownloadPackageVersionOptions downloadOptions; |
||||
|
||||
public DownloadPackageVersionStep( |
||||
BasePackage package, |
||||
string installPath, |
||||
DownloadPackageVersionOptions downloadOptions |
||||
) |
||||
{ |
||||
this.package = package; |
||||
this.installPath = installPath; |
||||
this.downloadOptions = downloadOptions; |
||||
} |
||||
|
||||
public Task ExecuteAsync(IProgress<ProgressReport>? progress = null) => |
||||
package.DownloadPackage(installPath, downloadOptions, progress); |
||||
|
||||
public string ProgressTitle => "Downloading package..."; |
||||
} |
@ -0,0 +1,14 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public interface IPackageModificationRunner |
||||
{ |
||||
Task ExecuteSteps(IReadOnlyList<IPackageStep> steps); |
||||
bool IsRunning { get; set; } |
||||
ProgressReport CurrentProgress { get; set; } |
||||
IPackageStep? CurrentStep { get; set; } |
||||
event EventHandler<ProgressReport>? ProgressChanged; |
||||
List<string> ConsoleOutput { get; } |
||||
Guid Id { get; } |
||||
} |
@ -0,0 +1,33 @@
|
||||
using StabilityMatrix.Core.Models.Packages; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Processes; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class InstallPackageStep : IPackageStep |
||||
{ |
||||
private readonly BasePackage package; |
||||
private readonly TorchVersion torchVersion; |
||||
private readonly string installPath; |
||||
|
||||
public InstallPackageStep(BasePackage package, TorchVersion torchVersion, string installPath) |
||||
{ |
||||
this.package = package; |
||||
this.torchVersion = torchVersion; |
||||
this.installPath = installPath; |
||||
} |
||||
|
||||
public async Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
void OnConsoleOutput(ProcessOutput output) |
||||
{ |
||||
progress?.Report(new ProgressReport { IsIndeterminate = true, Message = output.Text }); |
||||
} |
||||
|
||||
await package |
||||
.InstallPackage(installPath, torchVersion, progress, OnConsoleOutput) |
||||
.ConfigureAwait(false); |
||||
} |
||||
|
||||
public string ProgressTitle => "Installing package..."; |
||||
} |
@ -0,0 +1,43 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class PackageModificationRunner : IPackageModificationRunner |
||||
{ |
||||
public async Task ExecuteSteps(IReadOnlyList<IPackageStep> steps) |
||||
{ |
||||
IProgress<ProgressReport> progress = new Progress<ProgressReport>(report => |
||||
{ |
||||
CurrentProgress = report; |
||||
if (!string.IsNullOrWhiteSpace(report.Message)) |
||||
{ |
||||
ConsoleOutput.Add(report.Message); |
||||
} |
||||
|
||||
OnProgressChanged(report); |
||||
}); |
||||
|
||||
IsRunning = true; |
||||
foreach (var step in steps) |
||||
{ |
||||
CurrentStep = step; |
||||
await step.ExecuteAsync(progress).ConfigureAwait(false); |
||||
} |
||||
|
||||
progress.Report( |
||||
new ProgressReport(1f, message: "Package Install Complete", isIndeterminate: false) |
||||
); |
||||
|
||||
IsRunning = false; |
||||
} |
||||
|
||||
public bool IsRunning { get; set; } |
||||
public ProgressReport CurrentProgress { get; set; } |
||||
public IPackageStep? CurrentStep { get; set; } |
||||
public List<string> ConsoleOutput { get; } = new(); |
||||
public Guid Id { get; } = Guid.NewGuid(); |
||||
|
||||
public event EventHandler<ProgressReport>? ProgressChanged; |
||||
|
||||
protected virtual void OnProgressChanged(ProgressReport e) => ProgressChanged?.Invoke(this, e); |
||||
} |
@ -0,0 +1,9 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public interface IPackageStep |
||||
{ |
||||
Task ExecuteAsync(IProgress<ProgressReport>? progress = null); |
||||
string ProgressTitle { get; } |
||||
} |
@ -0,0 +1,24 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class SetPackageInstallingStep : IPackageStep |
||||
{ |
||||
private readonly ISettingsManager settingsManager; |
||||
private readonly string packageName; |
||||
|
||||
public SetPackageInstallingStep(ISettingsManager settingsManager, string packageName) |
||||
{ |
||||
this.settingsManager = settingsManager; |
||||
this.packageName = packageName; |
||||
} |
||||
|
||||
public Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
settingsManager.PackageInstallsInProgress.Add(packageName); |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
public string ProgressTitle => "Starting Package Installation"; |
||||
} |
@ -0,0 +1,32 @@
|
||||
using StabilityMatrix.Core.Models.Packages; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class SetupModelFoldersStep : IPackageStep |
||||
{ |
||||
private readonly BasePackage package; |
||||
private readonly SharedFolderMethod sharedFolderMethod; |
||||
private readonly string installPath; |
||||
|
||||
public SetupModelFoldersStep( |
||||
BasePackage package, |
||||
SharedFolderMethod sharedFolderMethod, |
||||
string installPath |
||||
) |
||||
{ |
||||
this.package = package; |
||||
this.sharedFolderMethod = sharedFolderMethod; |
||||
this.installPath = installPath; |
||||
} |
||||
|
||||
public async Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
progress?.Report( |
||||
new ProgressReport(-1f, "Setting up shared folder links...", isIndeterminate: true) |
||||
); |
||||
await package.SetupModelFolders(installPath, sharedFolderMethod).ConfigureAwait(false); |
||||
} |
||||
|
||||
public string ProgressTitle => "Setting up shared folder links..."; |
||||
} |
@ -0,0 +1,44 @@
|
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Python; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class SetupPrerequisitesStep : IPackageStep |
||||
{ |
||||
private readonly IPrerequisiteHelper prerequisiteHelper; |
||||
private readonly IPyRunner pyRunner; |
||||
|
||||
public SetupPrerequisitesStep(IPrerequisiteHelper prerequisiteHelper, IPyRunner pyRunner) |
||||
{ |
||||
this.prerequisiteHelper = prerequisiteHelper; |
||||
this.pyRunner = pyRunner; |
||||
} |
||||
|
||||
public async Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
// git, vcredist, etc... |
||||
await prerequisiteHelper.InstallAllIfNecessary(progress).ConfigureAwait(false); |
||||
|
||||
// python stuff |
||||
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled) |
||||
{ |
||||
progress?.Report( |
||||
new ProgressReport(-1f, "Installing Python prerequisites...", isIndeterminate: true) |
||||
); |
||||
|
||||
await pyRunner.Initialize().ConfigureAwait(false); |
||||
|
||||
if (!PyRunner.PipInstalled) |
||||
{ |
||||
await pyRunner.SetupPip().ConfigureAwait(false); |
||||
} |
||||
if (!PyRunner.VenvInstalled) |
||||
{ |
||||
await pyRunner.InstallPackage("virtualenv").ConfigureAwait(false); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public string ProgressTitle => "Installing prerequisites..."; |
||||
} |
@ -0,0 +1,175 @@
|
||||
using System.Diagnostics; |
||||
using System.Text.RegularExpressions; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Helper.Cache; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Processes; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.Packages; |
||||
|
||||
public class FooocusMre : BaseGitPackage |
||||
{ |
||||
public FooocusMre( |
||||
IGithubApiCache githubApi, |
||||
ISettingsManager settingsManager, |
||||
IDownloadService downloadService, |
||||
IPrerequisiteHelper prerequisiteHelper |
||||
) |
||||
: base(githubApi, settingsManager, downloadService, prerequisiteHelper) { } |
||||
|
||||
public override string Name => "Fooocus-MRE"; |
||||
public override string DisplayName { get; set; } = "Fooocus-MRE"; |
||||
public override string Author => "MoonRide303"; |
||||
|
||||
public override string Blurb => |
||||
"Fooocus-MRE is an image generating software, enhanced variant of the original Fooocus dedicated for a bit more advanced users"; |
||||
|
||||
public override string LicenseType => "GPL-3.0"; |
||||
|
||||
public override string LicenseUrl => |
||||
"https://github.com/MoonRide303/Fooocus-MRE/blob/moonride-main/LICENSE"; |
||||
public override string LaunchCommand => "launch.py"; |
||||
|
||||
public override Uri PreviewImageUri => |
||||
new( |
||||
"https://user-images.githubusercontent.com/130458190/265366059-ce430ea0-0995-4067-98dd-cef1d7dc1ab6.png" |
||||
); |
||||
|
||||
public override List<LaunchOptionDefinition> LaunchOptions => |
||||
new() |
||||
{ |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Port", |
||||
Type = LaunchOptionType.String, |
||||
Description = "Sets the listen port", |
||||
Options = { "--port" } |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Share", |
||||
Type = LaunchOptionType.Bool, |
||||
Description = "Set whether to share on Gradio", |
||||
Options = { "--share" } |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Listen", |
||||
Type = LaunchOptionType.String, |
||||
Description = "Set the listen interface", |
||||
Options = { "--listen" } |
||||
}, |
||||
LaunchOptionDefinition.Extras |
||||
}; |
||||
|
||||
public override SharedFolderMethod RecommendedSharedFolderMethod => SharedFolderMethod.Symlink; |
||||
|
||||
public override IEnumerable<SharedFolderMethod> AvailableSharedFolderMethods => |
||||
new[] { SharedFolderMethod.Symlink, SharedFolderMethod.None }; |
||||
|
||||
public override Dictionary<SharedFolderType, IReadOnlyList<string>> SharedFolders => |
||||
new() |
||||
{ |
||||
[SharedFolderType.StableDiffusion] = new[] { "models/checkpoints" }, |
||||
[SharedFolderType.Diffusers] = new[] { "models/diffusers" }, |
||||
[SharedFolderType.Lora] = new[] { "models/loras" }, |
||||
[SharedFolderType.CLIP] = new[] { "models/clip" }, |
||||
[SharedFolderType.TextualInversion] = new[] { "models/embeddings" }, |
||||
[SharedFolderType.VAE] = new[] { "models/vae" }, |
||||
[SharedFolderType.ApproxVAE] = new[] { "models/vae_approx" }, |
||||
[SharedFolderType.ControlNet] = new[] { "models/controlnet" }, |
||||
[SharedFolderType.GLIGEN] = new[] { "models/gligen" }, |
||||
[SharedFolderType.ESRGAN] = new[] { "models/upscale_models" }, |
||||
[SharedFolderType.Hypernetwork] = new[] { "models/hypernetworks" } |
||||
}; |
||||
|
||||
public override IEnumerable<TorchVersion> AvailableTorchVersions => |
||||
new[] { TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.Rocm }; |
||||
|
||||
public override async Task<string> GetLatestVersion() |
||||
{ |
||||
var release = await GetLatestRelease().ConfigureAwait(false); |
||||
return release.TagName!; |
||||
} |
||||
|
||||
public override async Task InstallPackage( |
||||
string installLocation, |
||||
TorchVersion torchVersion, |
||||
IProgress<ProgressReport>? progress = null, |
||||
Action<ProcessOutput>? onConsoleOutput = null |
||||
) |
||||
{ |
||||
await base.InstallPackage(installLocation, torchVersion, progress).ConfigureAwait(false); |
||||
var venvRunner = await SetupVenv(installLocation, forceRecreate: true) |
||||
.ConfigureAwait(false); |
||||
|
||||
progress?.Report(new ProgressReport(-1f, "Installing torch...", isIndeterminate: true)); |
||||
|
||||
var torchVersionStr = "cpu"; |
||||
|
||||
switch (torchVersion) |
||||
{ |
||||
case TorchVersion.Cuda: |
||||
torchVersionStr = "cu118"; |
||||
break; |
||||
case TorchVersion.Rocm: |
||||
torchVersionStr = "rocm5.4.2"; |
||||
break; |
||||
case TorchVersion.Cpu: |
||||
break; |
||||
default: |
||||
throw new ArgumentOutOfRangeException(nameof(torchVersion), torchVersion, null); |
||||
} |
||||
|
||||
await venvRunner |
||||
.PipInstall( |
||||
$"torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/{torchVersionStr}", |
||||
onConsoleOutput |
||||
) |
||||
.ConfigureAwait(false); |
||||
|
||||
progress?.Report( |
||||
new ProgressReport(-1f, "Installing requirements...", isIndeterminate: true) |
||||
); |
||||
await venvRunner |
||||
.PipInstall("-r requirements_versions.txt", onConsoleOutput) |
||||
.ConfigureAwait(false); |
||||
} |
||||
|
||||
public override async Task RunPackage( |
||||
string installedPackagePath, |
||||
string command, |
||||
string arguments, |
||||
Action<ProcessOutput>? onConsoleOutput |
||||
) |
||||
{ |
||||
await SetupVenv(installedPackagePath).ConfigureAwait(false); |
||||
|
||||
void HandleConsoleOutput(ProcessOutput s) |
||||
{ |
||||
onConsoleOutput?.Invoke(s); |
||||
|
||||
if (s.Text.Contains("Use the app with", StringComparison.OrdinalIgnoreCase)) |
||||
{ |
||||
var regex = new Regex(@"(https?:\/\/)([^:\s]+):(\d+)"); |
||||
var match = regex.Match(s.Text); |
||||
if (match.Success) |
||||
{ |
||||
WebUrl = match.Value; |
||||
} |
||||
OnStartupComplete(WebUrl); |
||||
} |
||||
} |
||||
|
||||
void HandleExit(int i) |
||||
{ |
||||
Debug.WriteLine($"Venv process exited with code {i}"); |
||||
OnExit(i); |
||||
} |
||||
|
||||
var args = $"\"{Path.Combine(installedPackagePath, command)}\" {arguments}"; |
||||
|
||||
VenvRunner?.RunDetached(args.TrimEnd(), HandleConsoleOutput, HandleExit); |
||||
} |
||||
} |
@ -0,0 +1,7 @@
|
||||
namespace StabilityMatrix.Core.Models.Packages; |
||||
|
||||
public class PackageVersionOptions |
||||
{ |
||||
public IEnumerable<PackageVersion>? AvailableVersions { get; set; } |
||||
public IEnumerable<PackageVersion>? AvailableBranches { get; set; } |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue