From bcc45f85ea84857b7fc502089f48d107fb9044f2 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 05:25:18 +0100 Subject: [PATCH 1/8] Readme cleanup --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1aab03c2..76ff6e65 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ [sdfx]: https://github.com/sdfxai/sdfx [fooocus-mashb1t]: https://github.com/mashb1t/Fooocus [reforge]: https://github.com/Panchovix/stable-diffusion-webui-reForge +[simplesdxl]: https://github.com/metercai/SimpleSDXL/ +[fluxgym]: https://github.com/cocktailpeanut/fluxgym [civitai]: https://civitai.com/ [huggingface]: https://huggingface.co/ @@ -47,7 +49,7 @@ Multi-Platform Package Manager and Inference UI for Stable Diffusion ### 🖱️ One click install and update for Stable Diffusion Web UI Packages - Supports: - [Stable Diffusion WebUI reForge][reforge], [Stable Diffusion WebUI Forge][forge], [Automatic 1111][auto1111], [Automatic 1111 DirectML][auto1111-directml], [SD Web UI-UX][webui-ux], [SD.Next][sdnext] - - [Fooocus][fooocus], [Fooocus MRE][fooocus-mre], [Fooocus ControlNet SDXL][fooocus-controlnet], [Ruined Fooocus][ruined-fooocus], [Fooocus - mashb1t's 1-Up Edition][fooocus-mashb1t], [SimpleSDXL](https://github.com/metercai/SimpleSDXL/) + - [Fooocus][fooocus], [Fooocus MRE][fooocus-mre], [Fooocus ControlNet SDXL][fooocus-controlnet], [Ruined Fooocus][ruined-fooocus], [Fooocus - mashb1t's 1-Up Edition][fooocus-mashb1t], [SimpleSDXL][simplesdxl] - [ComfyUI][comfy] - [StableSwarmUI][stable-swarm] - [VoltaML][voltaml] @@ -55,7 +57,7 @@ Multi-Platform Package Manager and Inference UI for Stable Diffusion - [SDFX][sdfx] - [Kohya's GUI][kohya-ss] - [OneTrainer][onetrainer] - - [FluxGym](https://github.com/cocktailpeanut/fluxgym) + - [FluxGym][fluxgym] - Manage plugins / extensions for supported packages ([Automatic1111][auto1111], [Comfy UI][comfy], [SD Web UI-UX][webui-ux], and [SD.Next][sdnext]) - Easily install or update Python dependencies for each package - Embedded Git and Python dependencies, with no need for either to be globally installed From 8f7163d2d46d46f486fb29e4b385fe2f0384aad3 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 05:27:57 +0100 Subject: [PATCH 2/8] add cogvideo to readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 76ff6e65..1a070fd3 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ [reforge]: https://github.com/Panchovix/stable-diffusion-webui-reForge [simplesdxl]: https://github.com/metercai/SimpleSDXL/ [fluxgym]: https://github.com/cocktailpeanut/fluxgym +[cogvideo]: https://github.com/THUDM/CogVideo +[cogstudio]: https://github.com/pinokiofactory/cogstudio [civitai]: https://civitai.com/ [huggingface]: https://huggingface.co/ @@ -58,6 +60,7 @@ Multi-Platform Package Manager and Inference UI for Stable Diffusion - [Kohya's GUI][kohya-ss] - [OneTrainer][onetrainer] - [FluxGym][fluxgym] + - [CogVideo][cogvideo] via [CogStudio][cogstudio] - Manage plugins / extensions for supported packages ([Automatic1111][auto1111], [Comfy UI][comfy], [SD Web UI-UX][webui-ux], and [SD.Next][sdnext]) - Easily install or update Python dependencies for each package - Embedded Git and Python dependencies, with no need for either to be globally installed From 477253c26b52298022be939be3e2a49dc79081f7 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 05:41:00 +0100 Subject: [PATCH 3/8] Add initial cogstudio package code --- .../Helper/Factory/PackageFactory.cs | 2 + .../Models/Packages/Cogstudio.cs | 145 ++++++++++++++++++ .../Models/SharedOutputType.cs | 1 + 3 files changed, 148 insertions(+) create mode 100644 StabilityMatrix.Core/Models/Packages/Cogstudio.cs diff --git a/StabilityMatrix.Core/Helper/Factory/PackageFactory.cs b/StabilityMatrix.Core/Helper/Factory/PackageFactory.cs index e842c643..e854bf23 100644 --- a/StabilityMatrix.Core/Helper/Factory/PackageFactory.cs +++ b/StabilityMatrix.Core/Helper/Factory/PackageFactory.cs @@ -92,6 +92,8 @@ public BasePackage GetNewBasePackage(InstalledPackage installedPackage) "FluxGym" => new FluxGym(githubApiCache, settingsManager, downloadService, prerequisiteHelper), "SimpleSDXL" => new SimpleSDXL(githubApiCache, settingsManager, downloadService, prerequisiteHelper), + "Cogstudio" + => new Cogstudio(githubApiCache, settingsManager, downloadService, prerequisiteHelper), _ => throw new ArgumentOutOfRangeException(nameof(installedPackage)) }; } diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs new file mode 100644 index 00000000..da4b310d --- /dev/null +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -0,0 +1,145 @@ +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 Cogstudio( + IGithubApiCache githubApi, + ISettingsManager settingsManager, + IDownloadService downloadService, + IPrerequisiteHelper prerequisiteHelper +) + : BaseGitPackage(githubApi, settingsManager, downloadService, prerequisiteHelper), + ISharedFolderLayoutPackage +{ + public override string Name => "CogVideo"; + public override string DisplayName { get; set; } = "Cogstudio"; + public override string Author => "THUDM"; + public override string Blurb => + "An advanced gradio web ui for generating and editing videos with CogVideo."; + public override string LicenseType => "Apache-2.0"; + public override string LicenseUrl => "https://github.com/THUDM/CogVideo/blob/main/LICENSE"; + public override string LaunchCommand => "inference/gradio_composite_demo/cogstudio.py"; + public override Uri PreviewImageUri => + new("https://raw.githubusercontent.com/pinokiofactory/cogstudio/main/img2vid.gif"); + + public override List LaunchOptions => new() { LaunchOptionDefinition.Extras }; + + public override SharedFolderMethod RecommendedSharedFolderMethod => SharedFolderMethod.None; + public override IEnumerable AvailableSharedFolderMethods => + new[] { SharedFolderMethod.None }; + public override Dictionary> SharedFolders => + ((ISharedFolderLayoutPackage)this).LegacySharedFolders; + public virtual SharedFolderLayout SharedFolderLayout => new() { }; + public override Dictionary> SharedOutputFolders => + new() { [SharedOutputType.Text2Vid] = new[] { "inference/gradio_composite_demo/output" } }; + + public override IEnumerable AvailableTorchIndices => + new[] { TorchIndex.Cpu, TorchIndex.Cuda }; + public override string MainBranch => "main"; + public override bool ShouldIgnoreReleases => true; + public override string OutputFolderName => "inference/gradio_composite_demo/output"; + public override PackageDifficulty InstallerSortOrder => PackageDifficulty.Simple; + + public override async Task InstallPackage( + string installLocation, + InstalledPackage installedPackage, + InstallPackageOptions options, + IProgress? progress = null, + Action? onConsoleOutput = null, + CancellationToken cancellationToken = default + ) + { + const string cogstudioUrl = + "https://raw.githubusercontent.com/pinokiofactory/cogstudio/refs/heads/main/cogstudio.py"; + + progress?.Report(new ProgressReport(-1f, "Setting up venv", isIndeterminate: true)); + await using var venvRunner = await SetupVenvPure(installLocation).ConfigureAwait(false); + + progress?.Report(new ProgressReport(-1f, "Setting up Cogstudio files", isIndeterminate: true)); + var gradioCompositeDemo = new FilePath(installLocation, "inference/gradio_composite_demo"); + gradioCompositeDemo.Directory?.Create(); + await DownloadService + .DownloadToFileAsync( + cogstudioUrl, + new FilePath(gradioCompositeDemo, "cogstudio.py"), + cancellationToken: cancellationToken + ) + .ConfigureAwait(false); + + progress?.Report(new ProgressReport(-1f, "Installing requirements", isIndeterminate: true)); + var requirements = new FilePath(installLocation, "requirements.txt"); + var pipArgs = new PipInstallArgs() + .WithTorch("==2.3.1") + .WithTorchVision("==0.18.1") + .WithTorchAudio("==2.3.1") + .WithTorchExtraIndex("cu121") + .WithParsedFromRequirementsTxt( + await requirements.ReadAllTextAsync(cancellationToken).ConfigureAwait(false), + Compat.IsWindows ? "torch*|moviepy|SwissArmyTransformer" : "torch*|moviepy" + ); + + if (installedPackage.PipOverrides != null) + { + pipArgs = pipArgs.WithUserOverrides(installedPackage.PipOverrides); + } + + if (Compat.IsWindows) + { + await venvRunner + .PipInstall( + " https://github.com/daswer123/deepspeed-windows/releases/download/11.2/deepspeed-0.11.2+cuda121-cp310-cp310-win_amd64.whl", + onConsoleOutput + ) + .ConfigureAwait(false); + await venvRunner + .PipInstall("spandrel opencv-python scikit-video", onConsoleOutput) + .ConfigureAwait(false); + } + + await venvRunner.PipInstall(pipArgs, onConsoleOutput).ConfigureAwait(false); + await venvRunner.PipInstall("moviepy==2.0.0.dev2", onConsoleOutput).ConfigureAwait(false); + } + + public override async Task RunPackage( + string installLocation, + InstalledPackage installedPackage, + RunPackageOptions options, + Action? onConsoleOutput = null, + CancellationToken cancellationToken = default + ) + { + await SetupVenv(installLocation).ConfigureAwait(false); + + void HandleConsoleOutput(ProcessOutput s) + { + onConsoleOutput?.Invoke(s); + + if (s.Text.Contains("Running on local URL", StringComparison.OrdinalIgnoreCase)) + { + var regex = new Regex(@"(https?:\/\/)([^:\s]+):(\d+)"); + var match = regex.Match(s.Text); + + if (match.Success) + { + WebUrl = match.Value; + } + OnStartupComplete(WebUrl); + } + } + + VenvRunner.RunDetached( + [Path.Combine(installLocation, options.Command ?? LaunchCommand), ..options.Arguments], + HandleConsoleOutput, + OnExit + ); + } +} diff --git a/StabilityMatrix.Core/Models/SharedOutputType.cs b/StabilityMatrix.Core/Models/SharedOutputType.cs index c533de49..c2b7b082 100644 --- a/StabilityMatrix.Core/Models/SharedOutputType.cs +++ b/StabilityMatrix.Core/Models/SharedOutputType.cs @@ -4,6 +4,7 @@ public enum SharedOutputType { All, Text2Img, + Text2Vid, Img2Img, Extras, Text2ImgGrids, From e5ecd8f00c9721763875f7fdf62a94906fbe06d4 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 05:53:01 +0100 Subject: [PATCH 4/8] resolve code warning --- StabilityMatrix.Core/Models/Packages/Cogstudio.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs index da4b310d..4e539057 100644 --- a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -38,7 +38,7 @@ IPrerequisiteHelper prerequisiteHelper new[] { SharedFolderMethod.None }; public override Dictionary> SharedFolders => ((ISharedFolderLayoutPackage)this).LegacySharedFolders; - public virtual SharedFolderLayout SharedFolderLayout => new() { }; + public virtual SharedFolderLayout SharedFolderLayout => new(); public override Dictionary> SharedOutputFolders => new() { [SharedOutputType.Text2Vid] = new[] { "inference/gradio_composite_demo/output" } }; @@ -92,6 +92,7 @@ await requirements.ReadAllTextAsync(cancellationToken).ConfigureAwait(false), pipArgs = pipArgs.WithUserOverrides(installedPackage.PipOverrides); } + // SwissArmyTransformer is not available on Windows and DeepSpeed needs prebuilt wheels if (Compat.IsWindows) { await venvRunner From c4149614b5fd57857b390f827197f0ec9fa065d0 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 06:18:15 +0100 Subject: [PATCH 5/8] consistent pkg name --- StabilityMatrix.Core/Models/Packages/Cogstudio.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs index 4e539057..235daf5b 100644 --- a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -20,9 +20,11 @@ IPrerequisiteHelper prerequisiteHelper : BaseGitPackage(githubApi, settingsManager, downloadService, prerequisiteHelper), ISharedFolderLayoutPackage { - public override string Name => "CogVideo"; + public override string Name => "Cogstudio"; public override string DisplayName { get; set; } = "Cogstudio"; - public override string Author => "THUDM"; + public override string RepositoryName => "CogVideo"; + public override string RepositoryAuthor => "THUDM"; + public override string Author => "pinokiofactory"; public override string Blurb => "An advanced gradio web ui for generating and editing videos with CogVideo."; public override string LicenseType => "Apache-2.0"; @@ -30,9 +32,7 @@ IPrerequisiteHelper prerequisiteHelper public override string LaunchCommand => "inference/gradio_composite_demo/cogstudio.py"; public override Uri PreviewImageUri => new("https://raw.githubusercontent.com/pinokiofactory/cogstudio/main/img2vid.gif"); - public override List LaunchOptions => new() { LaunchOptionDefinition.Extras }; - public override SharedFolderMethod RecommendedSharedFolderMethod => SharedFolderMethod.None; public override IEnumerable AvailableSharedFolderMethods => new[] { SharedFolderMethod.None }; @@ -41,7 +41,6 @@ IPrerequisiteHelper prerequisiteHelper public virtual SharedFolderLayout SharedFolderLayout => new(); public override Dictionary> SharedOutputFolders => new() { [SharedOutputType.Text2Vid] = new[] { "inference/gradio_composite_demo/output" } }; - public override IEnumerable AvailableTorchIndices => new[] { TorchIndex.Cpu, TorchIndex.Cuda }; public override string MainBranch => "main"; @@ -84,7 +83,7 @@ await DownloadService .WithTorchExtraIndex("cu121") .WithParsedFromRequirementsTxt( await requirements.ReadAllTextAsync(cancellationToken).ConfigureAwait(false), - Compat.IsWindows ? "torch*|moviepy|SwissArmyTransformer" : "torch*|moviepy" + excludePattern: Compat.IsWindows ? "torch*|moviepy|SwissArmyTransformer" : "torch*|moviepy" ); if (installedPackage.PipOverrides != null) From 71c47da8db298f94169880ff40ab90f981c1bacf Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 06:26:29 +0100 Subject: [PATCH 6/8] Fix pkg filter regex --- StabilityMatrix.Core/Models/Packages/Cogstudio.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs index 235daf5b..e9b41475 100644 --- a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -83,7 +83,9 @@ await DownloadService .WithTorchExtraIndex("cu121") .WithParsedFromRequirementsTxt( await requirements.ReadAllTextAsync(cancellationToken).ConfigureAwait(false), - excludePattern: Compat.IsWindows ? "torch*|moviepy|SwissArmyTransformer" : "torch*|moviepy" + excludePattern: Compat.IsWindows + ? "torch.*|moviepy.*|SwissArmyTransformer.*" + : "torch.*|moviepy.*" ); if (installedPackage.PipOverrides != null) From 5e45b709c06b952574e0932071d4001cbfd85ac0 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sun, 27 Oct 2024 06:56:07 +0100 Subject: [PATCH 7/8] fix output folder mapping (its not nested) --- StabilityMatrix.Core/Models/Packages/Cogstudio.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs index e9b41475..1e946cca 100644 --- a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -40,12 +40,12 @@ IPrerequisiteHelper prerequisiteHelper ((ISharedFolderLayoutPackage)this).LegacySharedFolders; public virtual SharedFolderLayout SharedFolderLayout => new(); public override Dictionary> SharedOutputFolders => - new() { [SharedOutputType.Text2Vid] = new[] { "inference/gradio_composite_demo/output" } }; + new() { [SharedOutputType.Text2Vid] = new[] { "output" } }; public override IEnumerable AvailableTorchIndices => new[] { TorchIndex.Cpu, TorchIndex.Cuda }; public override string MainBranch => "main"; public override bool ShouldIgnoreReleases => true; - public override string OutputFolderName => "inference/gradio_composite_demo/output"; + public override string OutputFolderName => "output"; public override PackageDifficulty InstallerSortOrder => PackageDifficulty.Simple; public override async Task InstallPackage( From 3a449984269f653585b87283d8574e3ef76bc4e9 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Sat, 16 Nov 2024 21:30:46 +0100 Subject: [PATCH 8/8] allow output folder path --- .../Models/Packages/Cogstudio.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs index 1e946cca..4d0b0c8c 100644 --- a/StabilityMatrix.Core/Models/Packages/Cogstudio.cs +++ b/StabilityMatrix.Core/Models/Packages/Cogstudio.cs @@ -65,15 +65,31 @@ public override async Task InstallPackage( progress?.Report(new ProgressReport(-1f, "Setting up Cogstudio files", isIndeterminate: true)); var gradioCompositeDemo = new FilePath(installLocation, "inference/gradio_composite_demo"); + var cogstudioFile = new FilePath(gradioCompositeDemo, "cogstudio.py"); gradioCompositeDemo.Directory?.Create(); await DownloadService - .DownloadToFileAsync( - cogstudioUrl, - new FilePath(gradioCompositeDemo, "cogstudio.py"), - cancellationToken: cancellationToken - ) + .DownloadToFileAsync(cogstudioUrl, cogstudioFile, cancellationToken: cancellationToken) .ConfigureAwait(false); + progress?.Report( + new ProgressReport( + -1f, + "Patching cogstudio.py to allow writing to the output folder", + isIndeterminate: true + ) + ); + var outputDir = new FilePath(installLocation, "output"); + if (Compat.IsWindows) + { + outputDir = outputDir.ToString().Replace("\\", "\\\\"); + } + var cogstudioContent = await cogstudioFile.ReadAllTextAsync(cancellationToken).ConfigureAwait(false); + cogstudioContent = cogstudioContent.Replace( + "demo.launch()", + $"demo.launch(allowed_paths=['{outputDir}'])" + ); + await cogstudioFile.WriteAllTextAsync(cogstudioContent, cancellationToken).ConfigureAwait(false); + progress?.Report(new ProgressReport(-1f, "Installing requirements", isIndeterminate: true)); var requirements = new FilePath(installLocation, "requirements.txt"); var pipArgs = new PipInstallArgs()