Based on https://github.com/leejet/stable-diffusion.cpp
Install the StableDiffusion.NET-Nuget and at least one of the Backend-Packages.
If GPU-support is available it will prefer this over CPU.
If you want to add your own native-libraries or need more control over which backend to load, check the static Backends
class.
stable diffusion:
using DiffusionModel model = ModelBuilder.StableDiffusion(@"<path to model")
.WithVae(@"<optional path to vae>")
.WithMultithreading()
.Build();
flux:
using DiffusionModel model = ModelBuilder.Flux(@"<path to flux-model.gguf>",
@"<path to clip_l.safetensors>",
@"<path to t5xxl_fp16.safetensors>",
@"<path to ae.safetensors>")
.WithMultithreading()
.Build();
with default parameters:
IImage<ColorRGB> image = model.TextToImage("<prompt>");
with custom parameters:
IImage<ColorRGB> image = model.TextToImage("<prompt>", model.GetDefaultParameter().WithSeed(1234).WithSize(1344, 768));
File.WriteAllBytes("output.png", image.ToPng());
To process the resulting image further you can write your own extensions or install one of the HPPH-extension sets:
HPPH.System.Drawing
HPPH.SkiaSharp