From b2a77da330f014a0bc34aaf9ca221f8d4aaf6e6c Mon Sep 17 00:00:00 2001 From: SocketByte Date: Sun, 9 Oct 2022 23:01:33 +0200 Subject: [PATCH] Fix long prompts crashing the app --- README.md | 1 + SDToolkit/Generator.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f68ef27..89b5c19 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ All in one, batteries-included software to easily generate and upscale AI art using [Stable Diffusion](https://github.com/CompVis/stable-diffusion). ![Image](https://i.imgur.com/EyjdVXj.png) +![Image](https://i.imgur.com/kB3mL6e.png) ## Requirements / Info diff --git a/SDToolkit/Generator.cs b/SDToolkit/Generator.cs index dbf7b09..5fbda11 100644 --- a/SDToolkit/Generator.cs +++ b/SDToolkit/Generator.cs @@ -62,7 +62,13 @@ public static void GenerateFromPrompt(GeneratorConfig config) private static void Run(GeneratorConfig config) { - Directory.Delete(WorkingDirectory + "\\stable-diffusion\\outputs\\txt2img-samples", true); + var samplesDir = WorkingDirectory + "\\stable-diffusion\\outputs\\txt2img-samples"; + if (Directory.Exists(samplesDir)) + { + Directory.Delete(samplesDir, true); + } + + var path = DateTimeOffset.Now.ToUnixTimeSeconds().ToString(); config.GenerateButton.Invoke(new MethodInvoker(delegate () { @@ -89,7 +95,8 @@ private static void Run(GeneratorConfig config) var prompt = config.Prompt; var converted = string.Join("_", prompt.Split(' ')); - var images = Directory.GetFiles(WorkingDirectory + @"\stable-diffusion\outputs\txt2img-samples\" + converted, "*.png"); + var dir = Directory.GetDirectories(WorkingDirectory + @"\stable-diffusion\outputs\txt2img-samples\")[0]; + var images = Directory.GetFiles(dir, "*.png"); config.GenerateButton.Invoke(new MethodInvoker(delegate () {