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 |
||||
{ |
@ -1,249 +1,229 @@
|
||||
<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:ui="using:FluentAvalonia.UI.Controls" |
||||
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" |
||||
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs" |
||||
xmlns:packages="clr-namespace:StabilityMatrix.Core.Models.Packages;assembly=StabilityMatrix.Core" |
||||
xmlns:models="clr-namespace:StabilityMatrix.Core.Models;assembly=StabilityMatrix.Core" |
||||
xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight" |
||||
xmlns:database="clr-namespace:StabilityMatrix.Core.Models.Database;assembly=StabilityMatrix.Core" |
||||
xmlns:icons="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia" |
||||
x:DataType="dialogs:InstallerViewModel" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="500" |
||||
d:DataContext="{x:Static mocks:DesignData.InstallerViewModel}" |
||||
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.InstallerDialog"> |
||||
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:ui="using:FluentAvalonia.UI.Controls" |
||||
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" |
||||
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs" |
||||
xmlns:packages="clr-namespace:StabilityMatrix.Core.Models.Packages;assembly=StabilityMatrix.Core" |
||||
xmlns:models="clr-namespace:StabilityMatrix.Core.Models;assembly=StabilityMatrix.Core" |
||||
xmlns:database="clr-namespace:StabilityMatrix.Core.Models.Database;assembly=StabilityMatrix.Core" |
||||
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages" |
||||
x:DataType="dialogs:InstallerViewModel" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="700" |
||||
d:DataContext="{x:Static mocks:DesignData.InstallerViewModel}" |
||||
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.InstallerDialog"> |
||||
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,*"> |
||||
<!-- Close button --> |
||||
<Grid HorizontalAlignment="Right"> |
||||
<Button |
||||
Margin="0,8,8,0" |
||||
Classes="transparent" |
||||
IsEnabled="{Binding !InstallProgress.IsProgressVisible}" |
||||
Command="{Binding OnCloseButtonClick}" |
||||
icons:Attached.Icon="fa-solid fa-xmark"/> |
||||
<Grid MaxHeight="900" |
||||
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto" |
||||
ColumnDefinitions="*,Auto"> |
||||
<!-- Title and image --> |
||||
<Grid Grid.Row="0" Grid.Column="0" |
||||
Margin="16, 0, 0, 0" |
||||
RowDefinitions="Auto, Auto, Auto, Auto, Auto"> |
||||
<TextBlock Grid.Row="0" Text="{Binding SelectedPackage.DisplayName}" |
||||
FontSize="24" |
||||
Margin="0, 16, 0, 4" /> |
||||
<TextBlock Grid.Row="1" Text="{Binding SelectedPackage.Blurb}" |
||||
Margin="0, 0, 0, 4" /> |
||||
<TextBlock Grid.Row="2" Text="{Binding SelectedPackage.Disclaimer}" |
||||
Margin="0, 0, 0, 4" |
||||
TextWrapping="Wrap" |
||||
Foreground="{DynamicResource ThemeRedColor}" |
||||
IsVisible="{Binding SelectedPackage.Disclaimer, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" /> |
||||
<controls:BetterAdvancedImage Grid.Row="4" |
||||
Margin="0, 12,0,0" |
||||
Source="{Binding SelectedPackage.PreviewImageUri}" |
||||
HorizontalAlignment="Center" |
||||
MaxHeight="300" |
||||
MaxWidth="600" |
||||
Stretch="UniformToFill" /> |
||||
</Grid> |
||||
<StackPanel |
||||
Grid.Row="1" |
||||
Margin="16,8,16,0" |
||||
Orientation="Vertical" |
||||
DataContext="{Binding InstallProgress}" |
||||
IsVisible="{Binding IsProgressVisible}"> |
||||
|
||||
<TextBlock |
||||
HorizontalAlignment="Center" |
||||
Padding="8" |
||||
Text="{Binding Text}" /> |
||||
<ProgressBar |
||||
IsIndeterminate="{Binding IsIndeterminate}" |
||||
Maximum="100" |
||||
Width="500" |
||||
Value="{Binding Value}" /> |
||||
<TextBlock |
||||
FontSize="10" |
||||
HorizontalAlignment="Center" |
||||
Padding="4" |
||||
Text="{Binding Description}" |
||||
TextWrapping="Wrap" /> |
||||
</StackPanel> |
||||
|
||||
<Grid Grid.Row="2" HorizontalAlignment="Left" ColumnDefinitions="Auto,*,Auto"> |
||||
<ListBox |
||||
Margin="8,16" |
||||
IsEnabled="{Binding !InstallProgress.IsProgressVisible}" |
||||
ItemsSource="{Binding AvailablePackages}" |
||||
SelectedItem="{Binding SelectedPackage, Mode=TwoWay}"> |
||||
<Grid Grid.Column="0" Grid.Row="2" |
||||
Grid.ColumnSpan="2" |
||||
Margin="16,0,16,0" |
||||
RowDefinitions="Auto, Auto, Auto, Auto" |
||||
HorizontalAlignment="Center" |
||||
ColumnDefinitions="Auto, Auto, Auto, Auto"> |
||||
|
||||
<!--<ListView.Style> |
||||
<Style TargetType="ListView"> |
||||
<Setter Property="Background" Value="#191919" /> |
||||
</Style> |
||||
</ListView.Style>--> |
||||
|
||||
<ListBox.Template> |
||||
<ControlTemplate> |
||||
<!-- BorderBrush="{KeyboardFocusBorderColorBrush}" --> |
||||
<Border |
||||
BorderThickness="1" |
||||
CornerRadius="5"> |
||||
<ItemsPresenter /> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</ListBox.Template> |
||||
|
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type packages:BasePackage}"> |
||||
<StackPanel Margin="8" VerticalAlignment="Top"> |
||||
<TextBlock Margin="0,5,0,5" Text="{Binding DisplayName}" /> |
||||
<TextBlock Margin="0,0,0,5" Text="{Binding ByAuthor}" /> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</ListBox> |
||||
<Label Grid.Row="1" Grid.Column="0" |
||||
Margin="8,0" |
||||
Content="{x:Static lang:Resources.Label_DisplayName}" /> |
||||
<TextBox Grid.Row="2" Grid.Column="0" |
||||
MinWidth="250" |
||||
Margin="8,0" |
||||
VerticalAlignment="Stretch" |
||||
VerticalContentAlignment="Center" |
||||
Text="{Binding InstallName, Mode=TwoWay}" /> |
||||
|
||||
<StackPanel |
||||
MinWidth="400" |
||||
Grid.Column="1" |
||||
Margin="8,16,0,16" |
||||
Orientation="Vertical"> |
||||
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" |
||||
Orientation="Horizontal" |
||||
Margin="8" |
||||
IsVisible="{Binding ShowDuplicateWarning}"> |
||||
<ui:SymbolIcon |
||||
Foreground="{DynamicResource ThemeRedColor}" |
||||
Margin="0,0,8,0" |
||||
Symbol="Alert" /> |
||||
<TextBlock |
||||
FontSize="24" |
||||
FontWeight="Bold" |
||||
Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}" /> |
||||
<TextBlock FontSize="12" Text="{Binding SelectedPackage.ByAuthor, FallbackValue=by Automatic111}" /> |
||||
Foreground="{DynamicResource ThemeRedColor}" |
||||
TextAlignment="Left" |
||||
TextWrapping="Wrap"> |
||||
<Run Text="{x:Static lang:Resources.Label_InstallationWithThisNameExists}" /> |
||||
<LineBreak /> |
||||
<Run Text="{x:Static lang:Resources.Label_PleaseChooseDifferentName}" /> |
||||
</TextBlock> |
||||
</StackPanel> |
||||
|
||||
<Button |
||||
Background="Transparent" |
||||
BorderBrush="Transparent" |
||||
Command="{Binding ShowPreviewCommand}" |
||||
Content="UI Preview" |
||||
Padding="4" |
||||
Margin="0,8,0,0"> |
||||
<!--<Button.Style> |
||||
<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}"> |
||||
<Setter Property="Foreground"> |
||||
<Setter.Value> |
||||
<SolidColorBrush Color="{DynamicResource SystemAccentColorSecondary}" /> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</Button.Style>--> |
||||
</Button> |
||||
<!-- Version Selector --> |
||||
<Label Grid.Row="1" Grid.Column="1" |
||||
Content="{Binding ReleaseLabelText}" /> |
||||
<ui:FAComboBox Grid.Row="2" Grid.Column="1" |
||||
ItemsSource="{Binding AvailableVersions}" |
||||
MinWidth="250" |
||||
VerticalAlignment="Stretch" |
||||
SelectedItem="{Binding SelectedVersion}"> |
||||
<ui:FAComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type models:PackageVersion}"> |
||||
<TextBlock |
||||
Name="NameTextBlock" |
||||
VerticalAlignment="Center" |
||||
Text="{Binding TagName}" /> |
||||
</DataTemplate> |
||||
</ui:FAComboBox.ItemTemplate> |
||||
</ui:FAComboBox> |
||||
|
||||
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" |
||||
HorizontalAlignment="Center" |
||||
Orientation="Horizontal" Margin="0,8,0,8" |
||||
IsVisible="{Binding IsReleaseModeAvailable}"> |
||||
<ToggleButton |
||||
Content="{x:Static lang:Resources.Label_Releases}" |
||||
IsChecked="{Binding IsReleaseMode}" |
||||
IsEnabled="{Binding IsReleaseModeAvailable}" /> |
||||
<ToggleButton |
||||
Content="{x:Static lang:Resources.Label_Branches}" |
||||
IsChecked="{Binding !IsReleaseMode}" |
||||
Margin="8,0,0,0" /> |
||||
</StackPanel> |
||||
|
||||
<ui:HyperlinkButton Padding="4" |
||||
NavigateUri="{Binding SelectedPackage.LicenseUrl}"> |
||||
<TextBlock TextWrapping="Wrap"> |
||||
<Run Text="{Binding SelectedPackage.LicenseType, Mode=OneWay}" /> |
||||
<Run Text="License" /> |
||||
</TextBlock> |
||||
</ui:HyperlinkButton> |
||||
|
||||
<ui:HyperlinkButton Padding="4" |
||||
NavigateUri="{Binding SelectedPackage.GithubUrl}"> |
||||
<TextBlock TextWrapping="Wrap"> |
||||
<Run Text="GitHub Page:" /> |
||||
<Run Text="{Binding SelectedPackage.GithubUrl, Mode=OneWay}" TextDecorations="Underline" /> |
||||
</TextBlock> |
||||
</ui:HyperlinkButton> |
||||
|
||||
<TextBlock Text="{Binding SelectedPackage.Disclaimer}" |
||||
Padding="4" |
||||
Foreground="OrangeRed" |
||||
TextWrapping="Wrap" |
||||
IsVisible="{Binding SelectedPackage.Disclaimer, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/> |
||||
<!-- Advanced Options Button --> |
||||
<Button Grid.Row="2" Grid.Column="2" VerticalAlignment="Stretch" |
||||
Margin="8,0"> |
||||
<ui:SymbolIcon FontSize="16" Margin="4" Symbol="Settings" /> |
||||
<Button.Flyout> |
||||
<Flyout> |
||||
<!-- Advanced Options --> |
||||
<StackPanel Orientation="Vertical" |
||||
Margin="8" |
||||
IsVisible="{Binding !IsAdvancedMode}"> |
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8,0,0" |
||||
IsVisible="{Binding IsReleaseModeAvailable}"> |
||||
<ToggleButton |
||||
Content="Releases" |
||||
IsChecked="{Binding IsReleaseMode}" |
||||
IsEnabled="{Binding IsReleaseModeAvailable}" /> |
||||
<ToggleButton |
||||
Content="Branches" |
||||
IsChecked="{Binding !IsReleaseMode}" |
||||
Margin="8,0,0,0" /> |
||||
</StackPanel> |
||||
<Label Content="{x:Static lang:Resources.Label_AdvancedOptions}" |
||||
FontSize="18" |
||||
HorizontalAlignment="Center" |
||||
Margin="8,0,8,8" /> |
||||
|
||||
<StackPanel Margin="0,16,0,0" Orientation="Horizontal"> |
||||
<StackPanel Orientation="Vertical"> |
||||
<Label Content="{Binding ReleaseLabelText}" /> |
||||
<ComboBox |
||||
ItemsSource="{Binding AvailableVersions}" |
||||
MinWidth="200" |
||||
SelectedItem="{Binding SelectedVersion}"> |
||||
<ComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type models:PackageVersion}"> |
||||
<StackPanel Margin="8,0,0,0" VerticalAlignment="Top"> |
||||
<Label Content="{x:Static lang:Resources.Label_Commit}" |
||||
Margin="0,0,0,4" |
||||
IsVisible="{Binding !IsReleaseMode}" /> |
||||
<ui:FAComboBox |
||||
IsVisible="{Binding !IsReleaseMode}" |
||||
ItemsSource="{Binding AvailableCommits}" |
||||
MinWidth="200" |
||||
MinHeight="38" |
||||
SelectedItem="{Binding SelectedCommit}"> |
||||
<ui:FAComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type database:GitCommit}"> |
||||
<TextBlock |
||||
Margin="0,4,0,4" |
||||
Margin="8,4,0,4" |
||||
Name="NameTextBlock" |
||||
Text="{Binding TagName}" /> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ComboBox.ItemTemplate> |
||||
</ComboBox> |
||||
</StackPanel> |
||||
Text="{Binding ShortSha}" /> |
||||
</DataTemplate> |
||||
</ui:FAComboBox.ItemTemplate> |
||||
</ui:FAComboBox> |
||||
|
||||
<StackPanel |
||||
Margin="8,0,0,0" |
||||
Orientation="Vertical" |
||||
IsVisible="{Binding !IsReleaseMode}"> |
||||
<Label Content="Commit" /> |
||||
<ComboBox |
||||
ItemsSource="{Binding AvailableCommits}" |
||||
MinWidth="100" |
||||
SelectedItem="{Binding SelectedCommit}"> |
||||
<ComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type database:GitCommit}"> |
||||
<StackPanel Margin="8,0,0,0" VerticalAlignment="Top"> |
||||
<Label Content="{x:Static lang:Resources.Label_SharedModelFolderStrategy}" |
||||
Margin="0,8,0,4" /> |
||||
<ui:FAComboBox |
||||
ItemsSource="{Binding SelectedPackage.AvailableSharedFolderMethods}" |
||||
MinWidth="200" |
||||
MinHeight="38" |
||||
SelectedItem="{Binding SelectedSharedFolderMethod}"> |
||||
<ui:FAComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type models:SharedFolderMethod}"> |
||||
<TextBlock |
||||
Margin="0,4,0,4" |
||||
Name="NameTextBlock" |
||||
Text="{Binding Sha}" /> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ComboBox.ItemTemplate> |
||||
</ComboBox> |
||||
</StackPanel> |
||||
</StackPanel> |
||||
Margin="8,4,0,4" |
||||
Text="{Binding }" /> |
||||
</DataTemplate> |
||||
</ui:FAComboBox.ItemTemplate> |
||||
</ui:FAComboBox> |
||||
|
||||
<Label Content="{x:Static lang:Resources.Label_PyTorchVersion}" |
||||
IsVisible="{Binding ShowTorchVersionOptions}" |
||||
Margin="0,8,0,4" /> |
||||
<ui:FAComboBox |
||||
ItemsSource="{Binding SelectedPackage.AvailableTorchVersions}" |
||||
MinWidth="200" |
||||
MinHeight="38" |
||||
IsVisible="{Binding ShowTorchVersionOptions}" |
||||
SelectedItem="{Binding SelectedTorchVersion}"> |
||||
<ui:FAComboBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type models:TorchVersion}"> |
||||
<TextBlock |
||||
Margin="8,4,0,4" |
||||
Text="{Binding }" /> |
||||
</DataTemplate> |
||||
</ui:FAComboBox.ItemTemplate> |
||||
</ui:FAComboBox> |
||||
</StackPanel> |
||||
</Flyout> |
||||
</Button.Flyout> |
||||
</Button> |
||||
</Grid> |
||||
|
||||
<Label Content="Display Name" Margin="0,16,0,0" /> |
||||
<StackPanel Orientation="Horizontal" IsVisible="{Binding ShowDuplicateWarning}"> |
||||
<ui:SymbolIcon |
||||
Foreground="{DynamicResource ThemeRedColor}" |
||||
Margin="8" |
||||
Symbol="Alert" /> |
||||
<TextBlock |
||||
Foreground="{DynamicResource ThemeRedColor}" |
||||
Margin="0,8,8,8" |
||||
TextAlignment="Left" |
||||
TextWrapping="Wrap"> |
||||
<Run Text="An installation with this name already exists." /> |
||||
<LineBreak /> |
||||
<Run Text="Please choose a different name or select a different Install Location." /> |
||||
</TextBlock> |
||||
</StackPanel> |
||||
|
||||
<TextBox |
||||
Margin="0,0,0,8" |
||||
Text="{Binding InstallName, Mode=TwoWay}" /> |
||||
<!-- Install Button --> |
||||
<UniformGrid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" |
||||
Columns="2" |
||||
Margin="0,32,0,0" |
||||
HorizontalAlignment="Center"> |
||||
<Button |
||||
Content="{x:Static lang:Resources.Action_Cancel}" |
||||
Command="{Binding Cancel}" |
||||
FontSize="20" |
||||
HorizontalAlignment="Center" |
||||
Margin="8,0,4,0" |
||||
Padding="16, 8, 16, 8" /> |
||||
<Button |
||||
Content="{x:Static lang:Resources.Action_Install}" |
||||
Command="{Binding InstallCommand}" |
||||
FontSize="20" |
||||
IsEnabled="{Binding CanInstall}" |
||||
HorizontalAlignment="Center" |
||||
Classes="success" |
||||
Margin="4,0,8,0" |
||||
Padding="16, 8, 16, 8" /> |
||||
</UniformGrid> |
||||
|
||||
<StackPanel Orientation="Horizontal"> |
||||
<Button |
||||
Command="{Binding InstallCommand}" |
||||
Content="Install" |
||||
Classes="success" |
||||
Height="50" |
||||
IsEnabled="{Binding !ShowDuplicateWarning}" |
||||
Margin="0,16,0,0" |
||||
VerticalAlignment="Top" |
||||
Width="100" /> |
||||
<controls:ProgressRing |
||||
Height="25" |
||||
IsIndeterminate="True" |
||||
BorderThickness="4" |
||||
Margin="8,16,0,0" |
||||
VerticalAlignment="Center" |
||||
IsVisible="{Binding InstallProgress.IsProgressVisible}" |
||||
Width="25" /> |
||||
<TextBlock |
||||
Margin="8,16,0,0" |
||||
Text="Installing..." |
||||
VerticalAlignment="Center" |
||||
IsVisible="{Binding InstallProgress.IsProgressVisible}" /> |
||||
</StackPanel> |
||||
</StackPanel> |
||||
<ScrollViewer Grid.Column="2" |
||||
MaxWidth="300" |
||||
Margin="16" |
||||
MaxHeight="600"> |
||||
<mdxaml:MarkdownScrollViewer |
||||
Markdown="{Binding ReleaseNotes, Mode=OneWay}"/> |
||||
</ScrollViewer> |
||||
</Grid> |
||||
<!-- Available Packages --> |
||||
<ListBox Grid.Column="1" Grid.Row="0" |
||||
Margin="8, 16" |
||||
ItemsSource="{Binding AvailablePackages}" |
||||
SelectedItem="{Binding SelectedPackage}"> |
||||
<ListBox.Template> |
||||
<ControlTemplate> |
||||
<ItemsPresenter /> |
||||
</ControlTemplate> |
||||
</ListBox.Template> |
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate DataType="{x:Type packages:BasePackage}"> |
||||
<StackPanel Margin="8"> |
||||
<TextBlock Text="{Binding DisplayName}" /> |
||||
<TextBlock Text="{Binding ByAuthor}" /> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</ListBox> |
||||
</Grid> |
||||
|
||||
|
||||
</controls:UserControlBase> |
||||
|
@ -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); |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue