Skip to content

Commit 10eaaac

Browse files
committed
Add project files.
1 parent e6ccb83 commit 10eaaac

19 files changed

Lines changed: 2722 additions & 0 deletions

LICENSE

Lines changed: 746 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SDToolkit
2+
3+
All in one, batteries-included software to easily generate and upscale AI art using [Stable Diffusion](https://github.com/CompVis/stable-diffusion).
4+
5+
![Image](https://i.imgur.com/EyjdVXj.png)
6+
7+
## Requirements / Info
8+
9+
- OS: Windows 64-bit
10+
- At least 25GB of disk space
11+
- At least 8GB of GPU VRAM is recommended
12+
- At least 16GB of RAM is recommended
13+
- CUDA-enabled GPU is recommended (Nvidia)
14+
15+
Since SDToolkit is all-in-one software, the model, upscaling software (video2x) and execution environment (Conda/Python) is included in the setup.
16+
17+
Tested with i7-12700KF and GTX 1080 with full precision. (around 6.7GB of VRAM usage)
18+
19+
Half precision is recommended for RTX cards.
20+
21+
## Installation
22+
23+
Just download and run the setup from the Releases tab. Be reminded that it's a huge file, you should have at least 20-25GB of free disk space.
24+
25+
## License
26+
27+
The software is licensed under GNU Affero Public License and the SD model is licensed under CreativeML Open RAIL-M. You're required to accept both to use this software. You're free to use the generated art files for commercial purposes as long as they conform to the license terms and conditions.
28+
29+
## Used software/models
30+
31+
This software uses Stable Diffusion v1-4 model licensed under CreativeML Open RAIL-M.
32+
You're free to download it yourself at [CompVis's huggingface repository](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original).
33+
34+
Scripts and model execution software provided by [basujindal's fork of stable diffusion](https://github.com/basujindal/stable-diffusion/).
35+
36+
Upscaling model and algorithm is provided by [video2x](https://github.com/k4yt3x/video2x).

SDToolkit.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.32901.82
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDToolkit", "SDToolkit\SDToolkit.csproj", "{8A9E9DE0-C4B2-4DCF-8198-CB2CCBD58514}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8A9E9DE0-C4B2-4DCF-8198-CB2CCBD58514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8A9E9DE0-C4B2-4DCF-8198-CB2CCBD58514}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8A9E9DE0-C4B2-4DCF-8198-CB2CCBD58514}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8A9E9DE0-C4B2-4DCF-8198-CB2CCBD58514}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BF8F32F4-9FE7-4921-9050-AAA25636B2E5}
24+
EndGlobalSection
25+
EndGlobal

SDToolkit/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

SDToolkit/Generator.cs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace SDToolkit
13+
{
14+
class Generator
15+
{
16+
public static readonly string WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
17+
18+
public class GeneratorConfig
19+
{
20+
public string Prompt { get; set; }
21+
public int ResHeight { get; set; }
22+
public int ResWidth { get; set; }
23+
public int Seed { get; set; }
24+
public int Steps { get; set; }
25+
public string UpscalingAlgorithm { get; set; }
26+
public string Precision { get; set; }
27+
28+
public bool UseTurbo { get; set; }
29+
30+
public TextBox DebugTextBox { get; set; }
31+
public ProgressBar ProgressBar { get; set; }
32+
public Button GenerateButton { get; set; }
33+
public PictureBox[] PictureBoxes { get; set; }
34+
}
35+
36+
public static void PrintToDebug(TextBox debugBox, string message)
37+
{
38+
if (message == null)
39+
{
40+
return;
41+
}
42+
debugBox.Invoke(new MethodInvoker(delegate ()
43+
{
44+
if (message.Length <= 0)
45+
{
46+
return;
47+
}
48+
debugBox.AppendText(message + "\r\n");
49+
debugBox.ScrollToCaret();
50+
}));
51+
}
52+
53+
public static void GenerateFromPrompt(GeneratorConfig config)
54+
{
55+
new Thread(() =>
56+
{
57+
Thread.CurrentThread.IsBackground = true;
58+
59+
Run(config);
60+
}).Start();
61+
}
62+
63+
private static void Run(GeneratorConfig config)
64+
{
65+
Directory.Delete(WorkingDirectory + "\\stable-diffusion\\outputs\\txt2img-samples", true);
66+
67+
config.GenerateButton.Invoke(new MethodInvoker(delegate ()
68+
{
69+
config.GenerateButton.Text = "Generating...";
70+
}));
71+
72+
var process = new Process
73+
{
74+
StartInfo = new ProcessStartInfo
75+
{
76+
FileName = "cmd.exe",
77+
RedirectStandardInput = true,
78+
UseShellExecute = false,
79+
CreateNoWindow = true,
80+
RedirectStandardOutput = true,
81+
RedirectStandardError = true,
82+
WorkingDirectory = WorkingDirectory,
83+
},
84+
EnableRaisingEvents = true,
85+
};
86+
87+
process.Exited += (s, e) =>
88+
{
89+
var prompt = config.Prompt;
90+
var converted = string.Join("_", prompt.Split(' '));
91+
92+
var images = Directory.GetFiles(WorkingDirectory + @"\stable-diffusion\outputs\txt2img-samples\" + converted, "*.png");
93+
94+
config.GenerateButton.Invoke(new MethodInvoker(delegate ()
95+
{
96+
config.GenerateButton.Text = "Upscaling...";
97+
config.DebugTextBox.Clear();
98+
}));
99+
100+
Upscaler.Upscale(config, images);
101+
};
102+
103+
process.ErrorDataReceived += (s, e) =>
104+
{
105+
if (e.Data == null)
106+
{
107+
return;
108+
}
109+
if (e.Data.Contains("PLMS Sampler:"))
110+
{
111+
var percentage = e.Data.Split(':')[1].Split('%')[0].Trim();
112+
if (percentage.Length == 0)
113+
{
114+
return;
115+
}
116+
config.ProgressBar.Invoke(new MethodInvoker(delegate ()
117+
{
118+
config.ProgressBar.Value = int.Parse(percentage);
119+
}));
120+
121+
config.GenerateButton.Invoke(new MethodInvoker(delegate ()
122+
{
123+
config.GenerateButton.Text = "Generating... (" + percentage + "%)";
124+
}));
125+
}
126+
};
127+
128+
process.OutputDataReceived += (s, e) =>
129+
{
130+
PrintToDebug(config.DebugTextBox, e.Data);
131+
};
132+
133+
process.Start();
134+
process.BeginErrorReadLine();
135+
process.BeginOutputReadLine();
136+
137+
using (var sw = process.StandardInput)
138+
{
139+
if (sw.BaseStream.CanWrite)
140+
{
141+
sw.WriteLine("conda\\Scripts\\activate.bat");
142+
sw.WriteLine("activate ldm");
143+
sw.WriteLine("cd stable-diffusion");
144+
sw.WriteLine("python optimizedSD/optimized_txt2img.py --prompt \"" + config.Prompt + "\""
145+
+ " --H " + config.ResHeight
146+
+ " --W " + config.ResWidth
147+
+ " --seed " + config.Seed
148+
+ (config.UseTurbo ? " --turbo" : "")
149+
+ (config.Precision == "Full" ? " --precision full" : "")
150+
+ " --n_iter 1 --n_samples 8 --ddim_steps " + config.Steps);
151+
}
152+
}
153+
}
154+
}
155+
}

SDToolkit/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Windows.Forms;
6+
7+
namespace SDToolkit
8+
{
9+
static class Program
10+
{
11+
/// <summary>
12+
/// The main entry point for the application.
13+
/// </summary>
14+
[STAThread]
15+
static void Main()
16+
{
17+
Application.EnableVisualStyles();
18+
Application.SetCompatibleTextRenderingDefault(false);
19+
Application.Run(new Window());
20+
}
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SDToolkit")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SDToolkit")]
13+
[assembly: AssemblyCopyright("Copyright © 2022")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("8a9e9de0-c4b2-4dcf-8198-cb2ccbd58514")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

SDToolkit/Properties/Resources.Designer.cs

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)