diff --git a/StableDiffusion.NET/Native/Native.Load.cs b/StableDiffusion.NET/Native/Native.Load.cs
index 309d842..61ecb09 100644
--- a/StableDiffusion.NET/Native/Native.Load.cs
+++ b/StableDiffusion.NET/Native/Native.Load.cs
@@ -26,6 +26,18 @@ internal static partial class Native
#region Methods
+ internal static bool LoadNativeLibrary(string libraryPath)
+ {
+ if (_loadedLibraryHandle != nint.Zero) return true;
+ if (NativeLibrary.TryLoad(libraryPath, out nint handle))
+ {
+ _loadedLibraryHandle = handle;
+ return true;
+ }
+
+ return false;
+ }
+
private static nint ResolveDllImport(string libraryname, Assembly assembly, DllImportSearchPath? searchpath)
{
if (libraryname != LIB_NAME) return nint.Zero;
diff --git a/StableDiffusion.NET/StableDiffusionModel.cs b/StableDiffusion.NET/StableDiffusionModel.cs
index a82c3b7..05be613 100644
--- a/StableDiffusion.NET/StableDiffusionModel.cs
+++ b/StableDiffusion.NET/StableDiffusionModel.cs
@@ -91,6 +91,15 @@ public sealed unsafe class StableDiffusionModel : IDisposable
}
}
+ ///
+ /// Manually load the native stable diffusion library.
+ /// Once set, it will continue to be used for all instances.
+ ///
+ /// Path to the stable diffusion library.
+ /// Bool if the library loaded.
+ public static bool LoadNativeLibrary(string libraryPath)
+ => Native.LoadNativeLibrary(libraryPath);
+
public IImage TextToImage(string prompt, StableDiffusionParameter parameter)
{
ObjectDisposedException.ThrowIf(_disposed, this);