JT
9 months ago
committed by
GitHub
57 changed files with 2338 additions and 311 deletions
@ -0,0 +1,65 @@
|
||||
<Styles |
||||
xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:controls="using:StabilityMatrix.Avalonia.Controls" |
||||
xmlns:system="using:System" |
||||
xmlns:treeFileExplorer="clr-namespace:StabilityMatrix.Avalonia.Models.TreeFileExplorer" |
||||
xmlns:mock="clr-namespace:StabilityMatrix.Avalonia.DesignData" |
||||
xmlns:sg="clr-namespace:SpacedGridControl.Avalonia;assembly=SpacedGridControl.Avalonia" |
||||
xmlns:fluentIcons="clr-namespace:FluentIcons.Avalonia.Fluent;assembly=FluentIcons.Avalonia.Fluent"> |
||||
<Design.PreviewWith> |
||||
<StackPanel Spacing="16"> |
||||
<Panel Height="300" Margin="4"> |
||||
<controls:TreeFileExplorer |
||||
RootPath="{x:Static mock:DesignData.CurrentDirectory}" /> |
||||
</Panel> |
||||
|
||||
<Panel Height="300" Margin="4"> |
||||
<controls:TreeFileExplorer |
||||
IndexFiles="False" |
||||
CanSelectFiles="False" |
||||
RootPath="{x:Static mock:DesignData.CurrentDirectory}" /> |
||||
</Panel> |
||||
</StackPanel> |
||||
</Design.PreviewWith> |
||||
|
||||
<Style Selector="controls|TreeFileExplorer"> |
||||
<!-- Set Defaults --> |
||||
<Setter Property="Template"> |
||||
<ControlTemplate> |
||||
<Grid> |
||||
<TreeView |
||||
ScrollViewer.VerticalScrollBarVisibility="Auto" |
||||
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RootItem.Children}"> |
||||
<TreeView.DataTemplates> |
||||
<DataTemplate |
||||
DataType="treeFileExplorer:TreeFileExplorerFile"> |
||||
<sg:SpacedGrid ColumnDefinitions="Auto,*" RowSpacing="0" ColumnSpacing="4"> |
||||
<fluentIcons:SymbolIcon |
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}" |
||||
Symbol="Document" /> |
||||
<TextBlock |
||||
Grid.Column="1" |
||||
Text="{Binding Path.Name}" /> |
||||
</sg:SpacedGrid> |
||||
</DataTemplate> |
||||
<TreeDataTemplate |
||||
DataType="treeFileExplorer:TreeFileExplorerDirectory" |
||||
ItemsSource="{Binding Children}"> |
||||
<sg:SpacedGrid ColumnDefinitions="Auto,*" RowSpacing="0" ColumnSpacing="4"> |
||||
<fluentIcons:SymbolIcon |
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}" |
||||
IsFilled="True" |
||||
Symbol="Folder" /> |
||||
<TextBlock |
||||
Grid.Column="1" |
||||
Text="{Binding Path.Name}" /> |
||||
</sg:SpacedGrid> |
||||
</TreeDataTemplate> |
||||
</TreeView.DataTemplates> |
||||
</TreeView> |
||||
</Grid> |
||||
</ControlTemplate> |
||||
</Setter> |
||||
</Style> |
||||
</Styles> |
@ -0,0 +1,135 @@
|
||||
using Avalonia; |
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class TreeFileExplorer : TemplatedControl |
||||
{ |
||||
public static readonly StyledProperty<TreeFileExplorerDirectory?> RootItemProperty = |
||||
AvaloniaProperty.Register<TreeFileExplorer, TreeFileExplorerDirectory?>("RootItem"); |
||||
|
||||
public TreeFileExplorerDirectory? RootItem |
||||
{ |
||||
get => GetValue(RootItemProperty); |
||||
set => SetValue(RootItemProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<string?> RootPathProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
string? |
||||
>("RootPath"); |
||||
|
||||
public string? RootPath |
||||
{ |
||||
get => GetValue(RootPathProperty); |
||||
set => SetValue(RootPathProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<IPathObject?> SelectedPathProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
IPathObject? |
||||
>("SelectedPath"); |
||||
|
||||
public IPathObject? SelectedPath |
||||
{ |
||||
get => GetValue(SelectedPathProperty); |
||||
set => SetValue(SelectedPathProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<bool> CanSelectFilesProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
bool |
||||
>("CanSelectFiles", true); |
||||
|
||||
public bool CanSelectFiles |
||||
{ |
||||
get => GetValue(CanSelectFilesProperty); |
||||
set => SetValue(CanSelectFilesProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<bool> CanSelectFoldersProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
bool |
||||
>("CanSelectFolders", true); |
||||
|
||||
public bool CanSelectFolders |
||||
{ |
||||
get => GetValue(CanSelectFoldersProperty); |
||||
set => SetValue(CanSelectFoldersProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<bool> IndexFilesProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
bool |
||||
>("IndexFiles", true); |
||||
|
||||
public bool IndexFiles |
||||
{ |
||||
get => GetValue(IndexFilesProperty); |
||||
set => SetValue(IndexFilesProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<bool> IndexFoldersProperty = AvaloniaProperty.Register< |
||||
TreeFileExplorer, |
||||
bool |
||||
>("IndexFolders", true); |
||||
|
||||
public bool IndexFolders |
||||
{ |
||||
get => GetValue(IndexFoldersProperty); |
||||
set => SetValue(IndexFoldersProperty, value); |
||||
} |
||||
|
||||
private TreeFileExplorerOptions GetOptions() |
||||
{ |
||||
var options = TreeFileExplorerOptions.None; |
||||
|
||||
if (CanSelectFiles) |
||||
{ |
||||
options |= TreeFileExplorerOptions.CanSelectFiles; |
||||
} |
||||
if (CanSelectFolders) |
||||
{ |
||||
options |= TreeFileExplorerOptions.CanSelectFolders; |
||||
} |
||||
if (IndexFiles) |
||||
{ |
||||
options |= TreeFileExplorerOptions.IndexFiles; |
||||
} |
||||
if (IndexFolders) |
||||
{ |
||||
options |= TreeFileExplorerOptions.IndexFolders; |
||||
} |
||||
|
||||
return options; |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
||||
{ |
||||
base.OnApplyTemplate(e); |
||||
|
||||
if (RootItem is null) |
||||
{ |
||||
RootItem = RootPath is null |
||||
? null |
||||
: new TreeFileExplorerDirectory(new DirectoryPath(RootPath), GetOptions()); |
||||
} |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) |
||||
{ |
||||
base.OnPropertyChanged(change); |
||||
|
||||
if (change.Property == RootPathProperty) |
||||
{ |
||||
var path = change.GetNewValue<string?>(); |
||||
RootItem = path is null |
||||
? null |
||||
: new TreeFileExplorerDirectory(new DirectoryPath(path), GetOptions()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
|
||||
public class TreeFileExplorerDirectory(IPathObject path, TreeFileExplorerOptions options) |
||||
: TreeFileExplorerItem(path, options) |
||||
{ |
||||
public IEnumerable<TreeFileExplorerItem> Children => |
||||
GetChildren(Path, Options) |
||||
.OrderByDescending(item => item.Path is DirectoryPath) |
||||
.ThenBy(item => item.Path.Name); |
||||
|
||||
private static IEnumerable<TreeFileExplorerItem> GetChildren( |
||||
IPathObject pathObject, |
||||
TreeFileExplorerOptions options |
||||
) |
||||
{ |
||||
return pathObject switch |
||||
{ |
||||
FilePath => Enumerable.Empty<TreeFileExplorerItem>(), |
||||
DirectoryPath directoryPath => GetChildren(directoryPath, options), |
||||
_ => throw new NotSupportedException() |
||||
}; |
||||
} |
||||
|
||||
private static IEnumerable<TreeFileExplorerItem> GetChildren( |
||||
DirectoryPath directoryPath, |
||||
TreeFileExplorerOptions options |
||||
) |
||||
{ |
||||
if (options.HasFlag(TreeFileExplorerOptions.IndexFiles)) |
||||
{ |
||||
foreach (var file in directoryPath.EnumerateFiles()) |
||||
{ |
||||
yield return new TreeFileExplorerFile(file, options); |
||||
} |
||||
} |
||||
|
||||
if (options.HasFlag(TreeFileExplorerOptions.IndexFolders)) |
||||
{ |
||||
foreach (var directory in directoryPath.EnumerateDirectories()) |
||||
{ |
||||
yield return new TreeFileExplorerDirectory(directory, options); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,6 @@
|
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
|
||||
public class TreeFileExplorerFile(IPathObject path, TreeFileExplorerOptions options) |
||||
: TreeFileExplorerItem(path, options); |
@ -0,0 +1,10 @@
|
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
|
||||
public class TreeFileExplorerItem(IPathObject path, TreeFileExplorerOptions options) |
||||
{ |
||||
public IPathObject Path { get; } = path; |
||||
|
||||
public TreeFileExplorerOptions Options { get; } = options; |
||||
} |
@ -0,0 +1,15 @@
|
||||
using System; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
|
||||
[Flags] |
||||
public enum TreeFileExplorerOptions |
||||
{ |
||||
None = 0, |
||||
|
||||
IndexFiles = 1 << 5, |
||||
IndexFolders = 1 << 6, |
||||
|
||||
CanSelectFiles = 1 << 10, |
||||
CanSelectFolders = 1 << 11, |
||||
} |
@ -0,0 +1,8 @@
|
||||
namespace StabilityMatrix.Avalonia.Models.TreeFileExplorer; |
||||
|
||||
public enum TreeFileExplorerType |
||||
{ |
||||
None, |
||||
File, |
||||
Directory |
||||
} |
@ -1,3 +1,5 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
||||
<s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">Yes</s:String> |
||||
<s:String x:Key="/Default/CodeEditing/Localization/LocalizableInspector/@EntryValue">Pessimistic</s:String> |
||||
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">UI</s:String> |
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=controls_005Cpropertygrid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
||||
|
@ -0,0 +1,58 @@
|
||||
// The MIT License (MIT) |
||||
// |
||||
// Copyright (c) 2024 Stability AI |
||||
// |
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
// of this software and associated documentation files (the "Software"), to deal |
||||
// in the Software without restriction, including without limitation the rights |
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
// copies of the Software, and to permit persons to whom the Software is |
||||
// furnished to do so, subject to the following conditions: |
||||
// |
||||
// The above copyright notice and this permission notice shall be included in all |
||||
// copies or substantial portions of the Software. |
||||
// |
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
// SOFTWARE. |
||||
|
||||
// from https://github.com/Stability-AI/StableSwarmUI/blob/master/src/BuiltinExtensions/ComfyUIBackend/ComfyUISelfStartBackend.cs |
||||
|
||||
|
||||
using FreneticUtilities.FreneticDataSyntax; |
||||
|
||||
namespace StabilityMatrix.Core.Models.FDS; |
||||
|
||||
public class ComfyUiSelfStartSettings : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"The location of the 'main.py' file. Can be an absolute or relative path, but must end with 'main.py'.\nIf you used the installer, this should be 'dlbackend/ComfyUI/main.py'." |
||||
)] |
||||
public string StartScript = ""; |
||||
|
||||
[ConfigComment("Any arguments to include in the launch script.")] |
||||
public string ExtraArgs = ""; |
||||
|
||||
[ConfigComment( |
||||
"If unchecked, the system will automatically add some relevant arguments to the comfy launch. If checked, automatic args (other than port) won't be added." |
||||
)] |
||||
public bool DisableInternalArgs = false; |
||||
|
||||
[ConfigComment("If checked, will automatically keep the comfy backend up to date when launching.")] |
||||
public bool AutoUpdate = true; |
||||
|
||||
[ConfigComment( |
||||
"If checked, tells Comfy to generate image previews. If unchecked, previews will not be generated, and images won't show up until they're done." |
||||
)] |
||||
public bool EnablePreviews = true; |
||||
|
||||
[ConfigComment("Which GPU to use, if multiple are available.")] |
||||
public int GPU_ID = 0; |
||||
|
||||
[ConfigComment("How many extra requests may queue up on this backend while one is processing.")] |
||||
public int OverQueue = 1; |
||||
} |
@ -0,0 +1,380 @@
|
||||
// The MIT License (MIT) |
||||
// |
||||
// Copyright (c) 2024 Stability AI |
||||
// |
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
// of this software and associated documentation files (the "Software"), to deal |
||||
// in the Software without restriction, including without limitation the rights |
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
// copies of the Software, and to permit persons to whom the Software is |
||||
// furnished to do so, subject to the following conditions: |
||||
// |
||||
// The above copyright notice and this permission notice shall be included in all |
||||
// copies or substantial portions of the Software. |
||||
// |
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
// SOFTWARE. |
||||
|
||||
// from https://raw.githubusercontent.com/Stability-AI/StableSwarmUI/master/src/Core/Settings.cs |
||||
|
||||
|
||||
using FreneticUtilities.FreneticDataSyntax; |
||||
|
||||
namespace StabilityMatrix.Core.Models.FDS; |
||||
|
||||
/// <summary>Central default settings list.</summary> |
||||
public class StableSwarmSettings : AutoConfiguration |
||||
{ |
||||
[ConfigComment("Settings related to file paths.")] |
||||
public PathsData Paths = new(); |
||||
|
||||
[ConfigComment("Settings related to networking and the webserver.")] |
||||
public NetworkData Network = new(); |
||||
|
||||
[ConfigComment("Restrictions to apply to default users.")] |
||||
public UserRestriction DefaultUserRestriction = new(); |
||||
|
||||
[ConfigComment( |
||||
"Default settings for users (unless the user modifies them, if so permitted).\n(NOTE: Usually, don't edit this. Go to the 'User' tab to edit your User-Settings)." |
||||
)] |
||||
public User DefaultUser = new(); |
||||
|
||||
[ConfigComment("Settings related to backends.")] |
||||
public BackendData Backends = new(); |
||||
|
||||
[ConfigComment( |
||||
"If this is set to 'true', hides the installer page. If 'false', the installer page will be shown." |
||||
)] |
||||
public bool IsInstalled = false; |
||||
|
||||
[ConfigComment( |
||||
"Ratelimit, in milliseconds, between Nvidia GPU status queries. Default is 1000 ms (1 second)." |
||||
)] |
||||
public long NvidiaQueryRateLimitMS = 1000; |
||||
|
||||
[ConfigComment( |
||||
"How to launch the UI. If 'none', just quietly launch.\nIf 'web', launch your web-browser to the page.\nIf 'webinstall', launch web-browser to the install page.\nIf 'electron', launch the UI in an electron window (NOT YET IMPLEMENTED)." |
||||
)] |
||||
[ManualSettingsOptions(Impl = null, Vals = new string[] { "none", "web", "webinstall", "electron" })] |
||||
public string LaunchMode = "webinstall"; |
||||
|
||||
[ConfigComment("The minimum tier of logs that should be visible in the console.\nDefault is 'info'.")] |
||||
public string LogLevel = "Info"; |
||||
|
||||
[ConfigComment("Settings related to the User Interface.")] |
||||
public UIData UI = new(); |
||||
|
||||
[ConfigComment("Settings related to webhooks.")] |
||||
public WebHooksData WebHooks = new(); |
||||
|
||||
/// <summary>Settings related to backends.</summary> |
||||
public class BackendData : AutoConfiguration |
||||
{ |
||||
[ConfigComment("How many times to retry initializing a backend before giving up. Default is 3.")] |
||||
public int MaxBackendInitAttempts = 3; |
||||
|
||||
[ConfigComment( |
||||
"Safety check, the maximum duration all requests can be waiting for a backend before the system declares a backend handling failure." |
||||
)] |
||||
public int MaxTimeoutMinutes = 20; |
||||
|
||||
[ConfigComment( |
||||
"The maximum duration an individual request can be waiting on a backend to be available before giving up.\n" |
||||
+ "Not to be confused with 'MaxTimeoutMinutes' which requires backends be unresponsive for that duration, this duration includes requests that are merely waiting because other requests are queued." |
||||
+ "\nDefaults to 60 * 24 * 7 = 1 week (ultra-long max queue duration)." |
||||
)] |
||||
public int PerRequestTimeoutMinutes = 60 * 24 * 7; |
||||
|
||||
[ConfigComment( |
||||
"The maximum number of pending requests to continue forcing orderly processing of.\nOver this limit, requests may start going out of order." |
||||
)] |
||||
public int MaxRequestsForcedOrder = 20; |
||||
|
||||
[ConfigComment( |
||||
"How many minutes to wait after the last generation before automatically freeing up VRAM (to prevent issues with other programs).\nThis has the downside of a small added bit of time to load back onto VRAM at next usage.\nUse a decimal number to free after seconds.\nDefaults to 10 minutes." |
||||
)] |
||||
public double ClearVRAMAfterMinutes = 10; |
||||
|
||||
[ConfigComment( |
||||
"How many minutes to wait after the last generation before automatically freeing up system RAM (to prevent issues with other programs).\nThis has the downside of causing models to fully load from data drive at next usage.\nUse a decimal number to free after seconds.\nDefaults to 60 minutes (one hour)." |
||||
)] |
||||
public double ClearSystemRAMAfterMinutes = 60; |
||||
} |
||||
|
||||
/// <summary>Settings related to networking and the webserver.</summary> |
||||
public class NetworkData : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"What web host address to use. `localhost` means your PC only." |
||||
+ "\nLinux users may use `0.0.0.0` to mean accessible to anyone that can connect to your PC (ie LAN users, or the public if your firewall is open)." |
||||
+ "\nWindows users may use `*` for that, though it may require additional Windows firewall configuration." |
||||
+ "\nAdvanced server users may wish to manually specify a host bind address here." |
||||
)] |
||||
public string Host = "localhost"; |
||||
|
||||
[ConfigComment("What web port to use. Default is '7801'.")] |
||||
public int Port = 7801; |
||||
|
||||
[ConfigComment( |
||||
"If true, if the port is already in use, the server will try to find another port to use instead.\nIf false, the server will fail to start if the port is already in use." |
||||
)] |
||||
public bool PortCanChange = true; |
||||
|
||||
[ConfigComment( |
||||
"Backends are automatically assigned unique ports. This value selects which port number to start the assignment from.\nDefault is '7820'." |
||||
)] |
||||
public int BackendStartingPort = 7820; |
||||
} |
||||
|
||||
/// <summary>Settings related to file paths.</summary> |
||||
public class PathsData : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"Root path for model files. Use a full-formed path (starting with '/' or a Windows drive like 'C:') to use an absolute path.\nDefaults to 'Models'." |
||||
)] |
||||
public string ModelRoot = "Models"; |
||||
|
||||
[ConfigComment( |
||||
"The model folder to use within 'ModelRoot'.\nDefaults to 'Stable-Diffusion'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDModelFolder = "Stable-Diffusion"; |
||||
|
||||
[ConfigComment( |
||||
"The LoRA (or related adapter type) model folder to use within 'ModelRoot'.\nDefaults to 'Lora'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDLoraFolder = "Lora"; |
||||
|
||||
[ConfigComment( |
||||
"The VAE (autoencoder) model folder to use within 'ModelRoot'.\nDefaults to 'VAE'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDVAEFolder = "VAE"; |
||||
|
||||
[ConfigComment( |
||||
"The Embedding (eg textual inversion) model folder to use within 'ModelRoot'.\nDefaults to 'Embeddings'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDEmbeddingFolder = "Embeddings"; |
||||
|
||||
[ConfigComment( |
||||
"The ControlNets model folder to use within 'ModelRoot'.\nDefaults to 'controlnet'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDControlNetsFolder = "controlnet"; |
||||
|
||||
[ConfigComment( |
||||
"The CLIP Vision model folder to use within 'ModelRoot'.\nDefaults to 'clip_vision'.\nAbsolute paths work too." |
||||
)] |
||||
public string SDClipVisionFolder = "clip_vision"; |
||||
|
||||
[ConfigComment("Root path for data (user configs, etc).\nDefaults to 'Data'")] |
||||
public string DataPath = "Data"; |
||||
|
||||
[ConfigComment("Root path for output files (images, etc).\nDefaults to 'Output'")] |
||||
public string OutputPath = "Output"; |
||||
|
||||
[ConfigComment("The folder for wildcard (.txt) files, under Data.\nDefaults to 'Wildcards'")] |
||||
public string WildcardsFolder = "Wildcards"; |
||||
|
||||
[ConfigComment( |
||||
"When true, output paths always have the username as a folder.\nWhen false, this will be skipped.\nKeep this on in multi-user environments." |
||||
)] |
||||
public bool AppendUserNameToOutputPath = true; |
||||
} |
||||
|
||||
/// <summary>Settings to control restrictions on users.</summary> |
||||
public class UserRestriction : AutoConfiguration |
||||
{ |
||||
[ConfigComment("How many directories deep a user's custom OutPath can be.\nDefault is 5.")] |
||||
public int MaxOutPathDepth = 5; |
||||
|
||||
[ConfigComment("Which user-settings the user is allowed to modify.\nDefault is all of them.")] |
||||
public List<string> AllowedSettings = new() { "*" }; |
||||
|
||||
[ConfigComment( |
||||
"If true, the user is treated as a full admin.\nThis includes the ability to modify these settings." |
||||
)] |
||||
public bool Admin = false; |
||||
|
||||
[ConfigComment("If true, user may load models.\nIf false, they may only use already-loaded models.")] |
||||
public bool CanChangeModels = true; |
||||
|
||||
[ConfigComment( |
||||
"What models are allowed, as a path regex.\nDirectory-separator is always '/'. Can be '.*' for all, 'MyFolder/.*' for only within that folder, etc.\nDefault is all." |
||||
)] |
||||
public string AllowedModels = ".*"; |
||||
|
||||
[ConfigComment("Generic permission flags. '*' means all.\nDefault is all.")] |
||||
public List<string> PermissionFlags = new() { "*" }; |
||||
|
||||
[ConfigComment("How many images can try to be generating at the same time on this user.")] |
||||
public int MaxT2ISimultaneous = 32; |
||||
} |
||||
|
||||
/// <summary>Settings per-user.</summary> |
||||
public class User : AutoConfiguration |
||||
{ |
||||
public class OutPath : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"Builder for output file paths. Can use auto-filling placeholders like '[model]' for the model name, '[prompt]' for a snippet of prompt text, etc.\n" |
||||
+ "Full details in the docs: https://github.com/Stability-AI/StableSwarmUI/blob/master/docs/User%20Settings.md#path-format" |
||||
)] |
||||
public string Format = "raw/[year]-[month]-[day]/[hour][minute]-[prompt]-[model]-[seed]"; |
||||
|
||||
[ConfigComment("How long any one part can be.\nDefault is 40 characters.")] |
||||
public int MaxLenPerPart = 40; |
||||
} |
||||
|
||||
[ConfigComment("Settings related to output path building.")] |
||||
public OutPath OutPathBuilder = new(); |
||||
|
||||
public class FileFormatData : AutoConfiguration |
||||
{ |
||||
[ConfigComment("What format to save images in.\nDefault is '.jpg' (at 100% quality).")] |
||||
public string ImageFormat = "JPG"; |
||||
|
||||
[ConfigComment("Whether to store metadata into saved images.\nDefaults enabled.")] |
||||
public bool SaveMetadata = true; |
||||
|
||||
[ConfigComment( |
||||
"If set to non-0, adds DPI metadata to saved images.\n'72' is a good value for compatibility with some external software." |
||||
)] |
||||
public int DPI = 0; |
||||
|
||||
[ConfigComment( |
||||
"If set to true, a '.txt' file will be saved alongside images with the image metadata easily viewable.\nThis can work even if saving in the image is disabled. Defaults disabled." |
||||
)] |
||||
public bool SaveTextFileMetadata = false; |
||||
} |
||||
|
||||
[ConfigComment("Settings related to saved file format.")] |
||||
public FileFormatData FileFormat = new(); |
||||
|
||||
[ConfigComment("Whether your files save to server data drive or not.")] |
||||
public bool SaveFiles = true; |
||||
|
||||
[ConfigComment("If true, folders will be discard from starred image paths.")] |
||||
public bool StarNoFolders = false; |
||||
|
||||
[ConfigComment("What theme to use. Default is 'dark_dreams'.")] |
||||
public string Theme = "dark_dreams"; |
||||
|
||||
[ConfigComment( |
||||
"If enabled, batch size will be reset to 1 when parameters are loaded.\nThis can prevent accidents that might thrash your GPU or cause compatibility issues, especially for example when importing a comfy workflow.\nYou can still set the batch size at will in the GUI." |
||||
)] |
||||
public bool ResetBatchSizeToOne = false; |
||||
|
||||
public enum HintFormatOptions |
||||
{ |
||||
BUTTON, |
||||
HOVER, |
||||
NONE |
||||
} |
||||
|
||||
[ConfigComment("The format for parameter hints to display as.\nDefault is 'BUTTON'.")] |
||||
[SettingsOptions(Impl = typeof(SettingsOptionsAttribute.ForEnum<HintFormatOptions>))] |
||||
public string HintFormat = "BUTTON"; |
||||
|
||||
public class VAEsData : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"What VAE to use with SDXL models by default. Use 'None' to use the one in the model." |
||||
)] |
||||
[ManualSettingsOptions(Impl = null, Vals = new string[] { "None" })] |
||||
public string DefaultSDXLVAE = "None"; |
||||
|
||||
[ConfigComment( |
||||
"What VAE to use with SDv1 models by default. Use 'None' to use the one in the model." |
||||
)] |
||||
[ManualSettingsOptions(Impl = null, Vals = new string[] { "None" })] |
||||
public string DefaultSDv1VAE = "None"; |
||||
} |
||||
|
||||
[ConfigComment("Options to override default VAEs with.")] |
||||
public VAEsData VAEs = new(); |
||||
|
||||
[ConfigComment( |
||||
"When generating live previews, this is how many simultaneous generation requests can be waiting at one time." |
||||
)] |
||||
public int MaxSimulPreviews = 1; |
||||
|
||||
[ConfigComment( |
||||
"Set to a number above 1 to allow generations of multiple images to automatically generate square mini-grids when they're done." |
||||
)] |
||||
public int MaxImagesInMiniGrid = 1; |
||||
|
||||
[ConfigComment("How many images the history view should stop trying to load after.")] |
||||
public int MaxImagesInHistory = 1000; |
||||
|
||||
[ConfigComment( |
||||
"If true, the Image History view will cache small preview thumbnails of images.\nThis should make things run faster. You can turn it off if you don't want that." |
||||
)] |
||||
public bool ImageHistoryUsePreviews = true; |
||||
|
||||
[ConfigComment( |
||||
"Delay, in seconds, betweeen Generate Forever updates.\nIf the delay hits and a generation is still waiting, it will be skipped.\nDefault is 0.1 seconds." |
||||
)] |
||||
public double GenerateForeverDelay = 0.1; |
||||
|
||||
[ConfigComment("What language to display the UI in.\nDefault is 'en' (English).")] |
||||
public string Language = "en"; |
||||
} |
||||
|
||||
/// <summary>UI-related settings.</summary> |
||||
public class UIData : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"Optionally specify a (raw HTML) welcome message here. If specified, will override the automatic welcome messages." |
||||
)] |
||||
public string OverrideWelcomeMessage = ""; |
||||
} |
||||
|
||||
/// <summary>Webhook settings.</summary> |
||||
public class WebHooksData : AutoConfiguration |
||||
{ |
||||
[ConfigComment( |
||||
"Webhook to call (empty JSON POST) when queues are starting up from idle.\nLeave empty to disable any webhook.\nCall must return before the first generation starts." |
||||
)] |
||||
public string QueueStartWebhook = ""; |
||||
|
||||
[ConfigComment( |
||||
"Webhook to call (empty JSON POST) when all queues are done and the server is going idle.\nLeave empty to disable any webhook.\nCall must return before queuing may restart." |
||||
)] |
||||
public string QueueEndWebhook = ""; |
||||
|
||||
[ConfigComment( |
||||
"How long to wait (in seconds) after all queues are done before sending the queue end webhook.\nThis is useful to prevent rapid start+end calls." |
||||
)] |
||||
public double QueueEndDelay = 1; |
||||
} |
||||
} |
||||
|
||||
[AttributeUsage(AttributeTargets.Field)] |
||||
public class SettingsOptionsAttribute : Attribute |
||||
{ |
||||
public abstract class AbstractImpl |
||||
{ |
||||
public abstract string[] GetOptions { get; } |
||||
} |
||||
|
||||
public class ForEnum<T> : AbstractImpl |
||||
where T : Enum |
||||
{ |
||||
public override string[] GetOptions => Enum.GetNames(typeof(T)); |
||||
} |
||||
|
||||
public Type Impl; |
||||
|
||||
public virtual string[] Options => (Activator.CreateInstance(Impl) as AbstractImpl).GetOptions; |
||||
} |
||||
|
||||
[AttributeUsage(AttributeTargets.Field)] |
||||
public class ManualSettingsOptionsAttribute : SettingsOptionsAttribute |
||||
{ |
||||
public string[] Vals; |
||||
|
||||
public override string[] Options => Vals; |
||||
} |
@ -0,0 +1,9 @@
|
||||
namespace StabilityMatrix.Core.Models.Packages.Extensions; |
||||
|
||||
public class VladExtensionItem |
||||
{ |
||||
public required string Name { get; set; } |
||||
public required Uri Url { get; set; } |
||||
public string? Long { get; set; } |
||||
public string? Description { get; set; } |
||||
} |
@ -0,0 +1,129 @@
|
||||
using System.Text.Json.Nodes; |
||||
using StabilityMatrix.Core.Attributes; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Helper.Cache; |
||||
using StabilityMatrix.Core.Helper.HardwareInfo; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
using StabilityMatrix.Core.Models.Packages.Extensions; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Processes; |
||||
using StabilityMatrix.Core.Python; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.Packages; |
||||
|
||||
[Singleton(typeof(BasePackage))] |
||||
public class SDWebForge( |
||||
IGithubApiCache githubApi, |
||||
ISettingsManager settingsManager, |
||||
IDownloadService downloadService, |
||||
IPrerequisiteHelper prerequisiteHelper |
||||
) : A3WebUI(githubApi, settingsManager, downloadService, prerequisiteHelper) |
||||
{ |
||||
public override string Name => "stable-diffusion-webui-forge"; |
||||
public override string DisplayName { get; set; } = "Stable Diffusion WebUI Forge"; |
||||
public override string Author => "lllyasviel"; |
||||
|
||||
public override string Blurb => |
||||
"Stable Diffusion WebUI Forge is a platform on top of Stable Diffusion WebUI (based on Gradio) to make development easier, optimize resource management, and speed up inference."; |
||||
|
||||
public override string LicenseUrl => |
||||
"https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/LICENSE.txt"; |
||||
|
||||
public override Uri PreviewImageUri => |
||||
new( |
||||
"https://github.com/lllyasviel/stable-diffusion-webui-forge/assets/19834515/ca5e05ed-bd86-4ced-8662-f41034648e8c" |
||||
); |
||||
|
||||
public override string MainBranch => "main"; |
||||
public override bool ShouldIgnoreReleases => true; |
||||
public override IPackageExtensionManager ExtensionManager => null; |
||||
|
||||
public override List<LaunchOptionDefinition> LaunchOptions => |
||||
[ |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Always Offload from VRAM", |
||||
Type = LaunchOptionType.Bool, |
||||
Options = ["--always-offload-from-vram"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Always GPU", |
||||
Type = LaunchOptionType.Bool, |
||||
Options = ["--always-gpu"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Always CPU", |
||||
Type = LaunchOptionType.Bool, |
||||
Options = ["--always-cpu"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Use DirectML", |
||||
Type = LaunchOptionType.Bool, |
||||
InitialValue = HardwareHelper.PreferDirectML(), |
||||
Options = ["--directml"] |
||||
}, |
||||
LaunchOptionDefinition.Extras |
||||
]; |
||||
|
||||
public override IEnumerable<TorchVersion> AvailableTorchVersions => |
||||
new[] |
||||
{ |
||||
TorchVersion.Cpu, |
||||
TorchVersion.Cuda, |
||||
TorchVersion.DirectMl, |
||||
TorchVersion.Rocm, |
||||
TorchVersion.Mps |
||||
}; |
||||
|
||||
public override async Task InstallPackage( |
||||
string installLocation, |
||||
TorchVersion torchVersion, |
||||
SharedFolderMethod selectedSharedFolderMethod, |
||||
DownloadPackageVersionOptions versionOptions, |
||||
IProgress<ProgressReport>? progress = null, |
||||
Action<ProcessOutput>? onConsoleOutput = null |
||||
) |
||||
{ |
||||
progress?.Report(new ProgressReport(-1f, "Setting up venv", isIndeterminate: true)); |
||||
|
||||
var venvRunner = await SetupVenv(installLocation, forceRecreate: true).ConfigureAwait(false); |
||||
await venvRunner.PipInstall("--upgrade pip wheel", onConsoleOutput).ConfigureAwait(false); |
||||
|
||||
progress?.Report(new ProgressReport(-1f, "Installing requirements...", isIndeterminate: true)); |
||||
|
||||
var requirements = new FilePath(installLocation, "requirements_versions.txt"); |
||||
var pipArgs = new PipInstallArgs(); |
||||
if (torchVersion is TorchVersion.DirectMl) |
||||
{ |
||||
pipArgs = pipArgs.WithTorchDirectML(); |
||||
} |
||||
else |
||||
{ |
||||
pipArgs = pipArgs |
||||
.WithTorch("==2.1.2") |
||||
.WithTorchVision("==0.16.2") |
||||
.WithTorchExtraIndex( |
||||
torchVersion switch |
||||
{ |
||||
TorchVersion.Cpu => "cpu", |
||||
TorchVersion.Cuda => "cu121", |
||||
TorchVersion.Rocm => "rocm5.6", |
||||
TorchVersion.Mps => "nightly/cpu", |
||||
_ => throw new ArgumentOutOfRangeException(nameof(torchVersion), torchVersion, null) |
||||
} |
||||
); |
||||
} |
||||
|
||||
pipArgs = pipArgs.WithParsedFromRequirementsTxt( |
||||
await requirements.ReadAllTextAsync().ConfigureAwait(false), |
||||
excludePattern: "torch" |
||||
); |
||||
|
||||
await venvRunner.PipInstall(pipArgs, onConsoleOutput).ConfigureAwait(false); |
||||
progress?.Report(new ProgressReport(1f, "Install complete", isIndeterminate: false)); |
||||
} |
||||
} |
@ -0,0 +1,386 @@
|
||||
using System.Diagnostics; |
||||
using System.Text.RegularExpressions; |
||||
using FreneticUtilities.FreneticDataSyntax; |
||||
using StabilityMatrix.Core.Attributes; |
||||
using StabilityMatrix.Core.Exceptions; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Helper.Cache; |
||||
using StabilityMatrix.Core.Models.FDS; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Processes; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.Packages; |
||||
|
||||
[Singleton(typeof(BasePackage))] |
||||
public class StableSwarm( |
||||
IGithubApiCache githubApi, |
||||
ISettingsManager settingsManager, |
||||
IDownloadService downloadService, |
||||
IPrerequisiteHelper prerequisiteHelper |
||||
) : BaseGitPackage(githubApi, settingsManager, downloadService, prerequisiteHelper) |
||||
{ |
||||
private Process? dotnetProcess; |
||||
|
||||
public override string Name => "StableSwarmUI"; |
||||
public override string DisplayName { get; set; } = "StableSwarmUI"; |
||||
public override string Author => "Stability-AI"; |
||||
|
||||
public override string Blurb => |
||||
"A Modular Stable Diffusion Web-User-Interface, with an emphasis on making powertools easily accessible, high performance, and extensibility."; |
||||
|
||||
public override string LicenseType => "MIT"; |
||||
public override string LicenseUrl => |
||||
"https://github.com/Stability-AI/StableSwarmUI/blob/master/LICENSE.txt"; |
||||
public override string LaunchCommand => string.Empty; |
||||
public override Uri PreviewImageUri => |
||||
new( |
||||
"https://raw.githubusercontent.com/Stability-AI/StableSwarmUI/master/.github/images/stableswarmui.jpg" |
||||
); |
||||
public override string OutputFolderName => "Output"; |
||||
public override IEnumerable<SharedFolderMethod> AvailableSharedFolderMethods => |
||||
[SharedFolderMethod.Symlink, SharedFolderMethod.Configuration, SharedFolderMethod.None]; |
||||
public override SharedFolderMethod RecommendedSharedFolderMethod => SharedFolderMethod.Configuration; |
||||
public override bool OfferInOneClickInstaller => false; |
||||
|
||||
public override List<LaunchOptionDefinition> LaunchOptions => |
||||
[ |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Host", |
||||
Type = LaunchOptionType.String, |
||||
DefaultValue = "127.0.0.1", |
||||
Options = ["--host"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Port", |
||||
Type = LaunchOptionType.String, |
||||
DefaultValue = "7801", |
||||
Options = ["--port"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Ngrok Path", |
||||
Type = LaunchOptionType.String, |
||||
Options = ["--ngrok-path"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Ngrok Basic Auth", |
||||
Type = LaunchOptionType.String, |
||||
Options = ["--ngrok-basic-auth"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Cloudflared Path", |
||||
Type = LaunchOptionType.String, |
||||
Options = ["--cloudflared-path"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Proxy Region", |
||||
Type = LaunchOptionType.String, |
||||
Options = ["--proxy-region"] |
||||
}, |
||||
new LaunchOptionDefinition |
||||
{ |
||||
Name = "Launch Mode", |
||||
Type = LaunchOptionType.Bool, |
||||
Options = ["--launch-mode web", "--launch-mode webinstall"] |
||||
}, |
||||
LaunchOptionDefinition.Extras |
||||
]; |
||||
|
||||
public override Dictionary<SharedFolderType, IReadOnlyList<string>> SharedFolders => |
||||
new() |
||||
{ |
||||
[SharedFolderType.StableDiffusion] = ["Models/Stable-Diffusion"], |
||||
[SharedFolderType.Lora] = ["Models/Lora"], |
||||
[SharedFolderType.VAE] = ["Models/VAE"], |
||||
[SharedFolderType.TextualInversion] = ["Models/Embeddings"], |
||||
[SharedFolderType.ControlNet] = ["Models/controlnet"], |
||||
[SharedFolderType.InvokeClipVision] = ["Models/clip_vision"] |
||||
}; |
||||
public override Dictionary<SharedOutputType, IReadOnlyList<string>> SharedOutputFolders => |
||||
new() { [SharedOutputType.Text2Img] = [OutputFolderName] }; |
||||
public override string MainBranch => "master"; |
||||
public override bool ShouldIgnoreReleases => true; |
||||
public override IEnumerable<TorchVersion> AvailableTorchVersions => |
||||
[TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.DirectMl, TorchVersion.Rocm, TorchVersion.Mps]; |
||||
public override PackageDifficulty InstallerSortOrder => PackageDifficulty.Advanced; |
||||
public override IEnumerable<PackagePrerequisite> Prerequisites => |
||||
[ |
||||
PackagePrerequisite.Git, |
||||
PackagePrerequisite.Dotnet, |
||||
PackagePrerequisite.Python310, |
||||
PackagePrerequisite.VcRedist |
||||
]; |
||||
|
||||
private FilePath GetSettingsPath(string installLocation) => |
||||
Path.Combine(installLocation, "Data", "Settings.fds"); |
||||
|
||||
private FilePath GetBackendsPath(string installLocation) => |
||||
Path.Combine(installLocation, "Data", "Backends.fds"); |
||||
|
||||
public override async Task InstallPackage( |
||||
string installLocation, |
||||
TorchVersion torchVersion, |
||||
SharedFolderMethod selectedSharedFolderMethod, |
||||
DownloadPackageVersionOptions versionOptions, |
||||
IProgress<ProgressReport>? progress = null, |
||||
Action<ProcessOutput>? onConsoleOutput = null |
||||
) |
||||
{ |
||||
progress?.Report(new ProgressReport(-1f, "Installing StableSwarmUI...", isIndeterminate: true)); |
||||
|
||||
var comfy = settingsManager.Settings.InstalledPackages.FirstOrDefault( |
||||
x => x.PackageName == nameof(ComfyUI) |
||||
); |
||||
|
||||
if (comfy == null) |
||||
{ |
||||
throw new InvalidOperationException("ComfyUI must be installed to use StableSwarmUI"); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
await prerequisiteHelper |
||||
.RunDotnet( |
||||
[ |
||||
"nuget", |
||||
"add", |
||||
"source", |
||||
"https://api.nuget.org/v3/index.json", |
||||
"--name", |
||||
"\"NuGet official package source\"" |
||||
], |
||||
workingDirectory: installLocation, |
||||
onProcessOutput: onConsoleOutput |
||||
) |
||||
.ConfigureAwait(false); |
||||
} |
||||
catch (ProcessException e) |
||||
{ |
||||
// ignore, probably means the source is already there |
||||
} |
||||
|
||||
await prerequisiteHelper |
||||
.RunDotnet( |
||||
[ |
||||
"build", |
||||
"src/StableSwarmUI.csproj", |
||||
"--configuration", |
||||
"Release", |
||||
"-o", |
||||
"src/bin/live_release" |
||||
], |
||||
workingDirectory: installLocation, |
||||
onProcessOutput: onConsoleOutput |
||||
) |
||||
.ConfigureAwait(false); |
||||
|
||||
// set default settings |
||||
var settings = new StableSwarmSettings { IsInstalled = true }; |
||||
|
||||
if (selectedSharedFolderMethod is SharedFolderMethod.Configuration) |
||||
{ |
||||
settings.Paths = new StableSwarmSettings.PathsData |
||||
{ |
||||
ModelRoot = settingsManager.ModelsDirectory, |
||||
SDModelFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.StableDiffusion.ToString() |
||||
), |
||||
SDLoraFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.Lora.ToString() |
||||
), |
||||
SDVAEFolder = Path.Combine(settingsManager.ModelsDirectory, SharedFolderType.VAE.ToString()), |
||||
SDEmbeddingFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.TextualInversion.ToString() |
||||
), |
||||
SDControlNetsFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.ControlNet.ToString() |
||||
), |
||||
SDClipVisionFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.InvokeClipVision.ToString() |
||||
) |
||||
}; |
||||
} |
||||
|
||||
settings.Save(true).SaveToFile(GetSettingsPath(installLocation)); |
||||
|
||||
var backendsFile = new FDSSection(); |
||||
var dataSection = new FDSSection(); |
||||
dataSection.Set("type", "comfyui_selfstart"); |
||||
dataSection.Set("title", "StabilityMatrix ComfyUI Self-Start"); |
||||
dataSection.Set("enabled", true); |
||||
|
||||
var launchArgs = comfy.LaunchArgs ?? []; |
||||
var comfyArgs = string.Join( |
||||
' ', |
||||
launchArgs |
||||
.Select(arg => arg.ToArgString()?.TrimEnd()) |
||||
.Where(arg => !string.IsNullOrWhiteSpace(arg)) |
||||
); |
||||
|
||||
dataSection.Set( |
||||
"settings", |
||||
new ComfyUiSelfStartSettings |
||||
{ |
||||
StartScript = $"../{comfy.DisplayName}/main.py", |
||||
DisableInternalArgs = false, |
||||
AutoUpdate = false, |
||||
ExtraArgs = comfyArgs |
||||
}.Save(true) |
||||
); |
||||
|
||||
backendsFile.Set("0", dataSection); |
||||
backendsFile.SaveToFile(GetBackendsPath(installLocation)); |
||||
} |
||||
|
||||
public override async Task RunPackage( |
||||
string installedPackagePath, |
||||
string command, |
||||
string arguments, |
||||
Action<ProcessOutput>? onConsoleOutput |
||||
) |
||||
{ |
||||
var aspEnvVars = new Dictionary<string, string> |
||||
{ |
||||
["ASPNETCORE_ENVIRONMENT"] = "Production", |
||||
["ASPNETCORE_URLS"] = "http://*:7801" |
||||
}; |
||||
|
||||
void HandleConsoleOutput(ProcessOutput s) |
||||
{ |
||||
onConsoleOutput?.Invoke(s); |
||||
|
||||
if (s.Text.Contains("Starting webserver", StringComparison.OrdinalIgnoreCase)) |
||||
{ |
||||
var regex = new Regex(@"(https?:\/\/)([^:\s]+):(\d+)"); |
||||
var match = regex.Match(s.Text); |
||||
if (match.Success) |
||||
{ |
||||
WebUrl = match.Value; |
||||
} |
||||
OnStartupComplete(WebUrl); |
||||
} |
||||
} |
||||
|
||||
dotnetProcess = await prerequisiteHelper |
||||
.RunDotnet( |
||||
args: $"src{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}live_release{Path.DirectorySeparatorChar}StableSwarmUI.dll {arguments.TrimEnd()}", |
||||
workingDirectory: installedPackagePath, |
||||
envVars: aspEnvVars, |
||||
onProcessOutput: HandleConsoleOutput, |
||||
waitForExit: false |
||||
) |
||||
.ConfigureAwait(false); |
||||
} |
||||
|
||||
public override Task SetupModelFolders( |
||||
DirectoryPath installDirectory, |
||||
SharedFolderMethod sharedFolderMethod |
||||
) => |
||||
sharedFolderMethod switch |
||||
{ |
||||
SharedFolderMethod.Symlink |
||||
=> base.SetupModelFolders(installDirectory, SharedFolderMethod.Symlink), |
||||
SharedFolderMethod.Configuration => SetupModelFoldersConfig(installDirectory), // TODO |
||||
_ => Task.CompletedTask |
||||
}; |
||||
|
||||
public override Task RemoveModelFolderLinks( |
||||
DirectoryPath installDirectory, |
||||
SharedFolderMethod sharedFolderMethod |
||||
) => |
||||
sharedFolderMethod switch |
||||
{ |
||||
SharedFolderMethod.Symlink => base.RemoveModelFolderLinks(installDirectory, sharedFolderMethod), |
||||
SharedFolderMethod.Configuration => RemoveModelFoldersConfig(installDirectory), |
||||
_ => Task.CompletedTask |
||||
}; |
||||
|
||||
public override async Task WaitForShutdown() |
||||
{ |
||||
if (dotnetProcess is { HasExited: false }) |
||||
{ |
||||
dotnetProcess.Kill(true); |
||||
try |
||||
{ |
||||
await dotnetProcess |
||||
.WaitForExitAsync(new CancellationTokenSource(5000).Token) |
||||
.ConfigureAwait(false); |
||||
} |
||||
catch (OperationCanceledException e) |
||||
{ |
||||
Console.WriteLine(e); |
||||
} |
||||
} |
||||
|
||||
dotnetProcess = null; |
||||
GC.SuppressFinalize(this); |
||||
} |
||||
|
||||
private Task SetupModelFoldersConfig(DirectoryPath installDirectory) |
||||
{ |
||||
var settingsPath = GetSettingsPath(installDirectory); |
||||
var existingSettings = new StableSwarmSettings(); |
||||
var settingsExists = File.Exists(settingsPath); |
||||
if (settingsExists) |
||||
{ |
||||
var section = FDSUtility.ReadFile(settingsPath); |
||||
existingSettings.Load(section); |
||||
} |
||||
|
||||
existingSettings.Paths = new StableSwarmSettings.PathsData |
||||
{ |
||||
ModelRoot = settingsManager.ModelsDirectory, |
||||
SDModelFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.StableDiffusion.ToString() |
||||
), |
||||
SDLoraFolder = Path.Combine(settingsManager.ModelsDirectory, SharedFolderType.Lora.ToString()), |
||||
SDVAEFolder = Path.Combine(settingsManager.ModelsDirectory, SharedFolderType.VAE.ToString()), |
||||
SDEmbeddingFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.TextualInversion.ToString() |
||||
), |
||||
SDControlNetsFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.ControlNet.ToString() |
||||
), |
||||
SDClipVisionFolder = Path.Combine( |
||||
settingsManager.ModelsDirectory, |
||||
SharedFolderType.InvokeClipVision.ToString() |
||||
) |
||||
}; |
||||
|
||||
existingSettings.Save(true).SaveToFile(settingsPath); |
||||
|
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
private Task RemoveModelFoldersConfig(DirectoryPath installDirectory) |
||||
{ |
||||
var settingsPath = GetSettingsPath(installDirectory); |
||||
var existingSettings = new StableSwarmSettings(); |
||||
var settingsExists = File.Exists(settingsPath); |
||||
if (settingsExists) |
||||
{ |
||||
var section = FDSUtility.ReadFile(settingsPath); |
||||
existingSettings.Load(section); |
||||
} |
||||
|
||||
existingSettings.Paths = new StableSwarmSettings.PathsData(); |
||||
existingSettings.Save(true).SaveToFile(settingsPath); |
||||
|
||||
return Task.CompletedTask; |
||||
} |
||||
} |
Loading…
Reference in new issue