Browse Source
# Conflicts: # StabilityMatrix.Core/Converters/Json/DefaultUnknownEnumConverter.cspull/333/head
Ionite
12 months ago
27 changed files with 463 additions and 175 deletions
@ -0,0 +1,19 @@ |
|||||||
|
using CommunityToolkit.Mvvm.Input; |
||||||
|
using StabilityMatrix.Core.Processes; |
||||||
|
|
||||||
|
namespace StabilityMatrix.Avalonia.Helpers; |
||||||
|
|
||||||
|
public static class IOCommands |
||||||
|
{ |
||||||
|
public static RelayCommand<string?> OpenUrlCommand { get; } = |
||||||
|
new( |
||||||
|
url => |
||||||
|
{ |
||||||
|
if (string.IsNullOrWhiteSpace(url)) |
||||||
|
return; |
||||||
|
|
||||||
|
ProcessRunner.OpenUrl(url); |
||||||
|
}, |
||||||
|
url => !string.IsNullOrWhiteSpace(url) |
||||||
|
); |
||||||
|
} |
@ -1,12 +1,14 @@ |
|||||||
using System.Text.Json.Serialization; |
using System.Text.Json.Serialization; |
||||||
|
using StabilityMatrix.Core.Converters.Json; |
||||||
|
|
||||||
namespace StabilityMatrix.Core.Models.Api; |
namespace StabilityMatrix.Core.Models.Api; |
||||||
|
|
||||||
|
[JsonConverter(typeof(DefaultUnknownEnumConverter<CivitModelFormat>))] |
||||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
|
||||||
public enum CivitModelFormat |
public enum CivitModelFormat |
||||||
{ |
{ |
||||||
|
Unknown, |
||||||
SafeTensor, |
SafeTensor, |
||||||
PickleTensor, |
PickleTensor, |
||||||
|
Diffusers, |
||||||
Other |
Other |
||||||
} |
} |
||||||
|
@ -0,0 +1,72 @@ |
|||||||
|
using System.Diagnostics; |
||||||
|
using System.Text.RegularExpressions; |
||||||
|
using StabilityMatrix.Core.Attributes; |
||||||
|
using StabilityMatrix.Core.Helper; |
||||||
|
using StabilityMatrix.Core.Helper.Cache; |
||||||
|
using StabilityMatrix.Core.Models.FileInterfaces; |
||||||
|
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 RuinedFooocus : Fooocus |
||||||
|
{ |
||||||
|
public RuinedFooocus( |
||||||
|
IGithubApiCache githubApi, |
||||||
|
ISettingsManager settingsManager, |
||||||
|
IDownloadService downloadService, |
||||||
|
IPrerequisiteHelper prerequisiteHelper |
||||||
|
) |
||||||
|
: base(githubApi, settingsManager, downloadService, prerequisiteHelper) { } |
||||||
|
|
||||||
|
public override string Name => "RuinedFooocus"; |
||||||
|
public override string DisplayName { get; set; } = "RuinedFooocus"; |
||||||
|
public override string Author => "runew0lf"; |
||||||
|
public override string Blurb => |
||||||
|
"RuinedFooocus combines the best aspects of Stable Diffusion and Midjourney into one seamless, cutting-edge experience"; |
||||||
|
public override string LicenseUrl => |
||||||
|
"https://github.com/runew0lf/RuinedFooocus/blob/main/LICENSE"; |
||||||
|
public override Uri PreviewImageUri => |
||||||
|
new("https://raw.githubusercontent.com/runew0lf/pmmconfigs/main/RuinedFooocus_ss.png"); |
||||||
|
public override PackageDifficulty InstallerSortOrder => PackageDifficulty.Expert; |
||||||
|
|
||||||
|
public override async Task InstallPackage( |
||||||
|
string installLocation, |
||||||
|
TorchVersion torchVersion, |
||||||
|
SharedFolderMethod selectedSharedFolderMethod, |
||||||
|
DownloadPackageVersionOptions versionOptions, |
||||||
|
IProgress<ProgressReport>? progress = null, |
||||||
|
Action<ProcessOutput>? onConsoleOutput = null |
||||||
|
) |
||||||
|
{ |
||||||
|
if (torchVersion == TorchVersion.Cuda) |
||||||
|
{ |
||||||
|
var venvRunner = await SetupVenv(installLocation, forceRecreate: true) |
||||||
|
.ConfigureAwait(false); |
||||||
|
|
||||||
|
progress?.Report(new ProgressReport(-1f, "Installing torch...", isIndeterminate: true)); |
||||||
|
|
||||||
|
await InstallCudaTorch(venvRunner, progress, onConsoleOutput).ConfigureAwait(false); |
||||||
|
|
||||||
|
var requirements = new FilePath(installLocation, "requirements_versions.txt"); |
||||||
|
await venvRunner |
||||||
|
.PipInstallFromRequirements(requirements, onConsoleOutput, excludes: "torch") |
||||||
|
.ConfigureAwait(false); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
await base.InstallPackage( |
||||||
|
installLocation, |
||||||
|
torchVersion, |
||||||
|
selectedSharedFolderMethod, |
||||||
|
versionOptions, |
||||||
|
progress, |
||||||
|
onConsoleOutput |
||||||
|
) |
||||||
|
.ConfigureAwait(false); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
using System.Text.Json; |
||||||
|
using System.Text.Json.Serialization; |
||||||
|
using StabilityMatrix.Core.Converters.Json; |
||||||
|
|
||||||
|
namespace StabilityMatrix.Tests.Core; |
||||||
|
|
||||||
|
[TestClass] |
||||||
|
public class DefaultUnknownEnumConverterTests |
||||||
|
{ |
||||||
|
[TestMethod] |
||||||
|
[ExpectedException(typeof(JsonException))] |
||||||
|
public void TestDeserialize_NormalEnum_ShouldError() |
||||||
|
{ |
||||||
|
const string json = "\"SomeUnknownValue\""; |
||||||
|
|
||||||
|
JsonSerializer.Deserialize<NormalEnum>(json); |
||||||
|
} |
||||||
|
|
||||||
|
[TestMethod] |
||||||
|
public void TestDeserialize_UnknownEnum_ShouldConvert() |
||||||
|
{ |
||||||
|
const string json = "\"SomeUnknownValue\""; |
||||||
|
|
||||||
|
var result = JsonSerializer.Deserialize<UnknownEnum>(json); |
||||||
|
|
||||||
|
Assert.AreEqual(UnknownEnum.Unknown, result); |
||||||
|
} |
||||||
|
|
||||||
|
[TestMethod] |
||||||
|
public void TestDeserialize_DefaultEnum_ShouldConvert() |
||||||
|
{ |
||||||
|
const string json = "\"SomeUnknownValue\""; |
||||||
|
|
||||||
|
var result = JsonSerializer.Deserialize<DefaultEnum>(json); |
||||||
|
|
||||||
|
Assert.AreEqual(DefaultEnum.CustomDefault, result); |
||||||
|
} |
||||||
|
|
||||||
|
[TestMethod] |
||||||
|
public void TestSerialize_UnknownEnum_ShouldConvert() |
||||||
|
{ |
||||||
|
const string expected = "\"Unknown\""; |
||||||
|
|
||||||
|
var result = JsonSerializer.Serialize(UnknownEnum.Unknown); |
||||||
|
|
||||||
|
Assert.AreEqual(expected, result); |
||||||
|
} |
||||||
|
|
||||||
|
[TestMethod] |
||||||
|
public void TestSerialize_DefaultEnum_ShouldConvert() |
||||||
|
{ |
||||||
|
const string expected = "\"CustomDefault\""; |
||||||
|
|
||||||
|
var result = JsonSerializer.Serialize(DefaultEnum.CustomDefault); |
||||||
|
|
||||||
|
Assert.AreEqual(expected, result); |
||||||
|
} |
||||||
|
|
||||||
|
private enum NormalEnum |
||||||
|
{ |
||||||
|
Unknown, |
||||||
|
Value1, |
||||||
|
Value2 |
||||||
|
} |
||||||
|
|
||||||
|
[JsonConverter(typeof(DefaultUnknownEnumConverter<UnknownEnum>))] |
||||||
|
private enum UnknownEnum |
||||||
|
{ |
||||||
|
Unknown, |
||||||
|
Value1, |
||||||
|
Value2 |
||||||
|
} |
||||||
|
|
||||||
|
[JsonConverter(typeof(DefaultUnknownEnumConverter<DefaultEnum>))] |
||||||
|
private enum DefaultEnum |
||||||
|
{ |
||||||
|
CustomDefault, |
||||||
|
Value1, |
||||||
|
Value2 |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue