Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually loading SD library #19

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions StableDiffusion.NET/Native/Native.Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ static 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;
Expand Down
9 changes: 9 additions & 0 deletions StableDiffusion.NET/StableDiffusionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ private void Initialize()
}
}

/// <summary>
/// Manually load the native stable diffusion library.
/// Once set, it will continue to be used for all instances.
/// </summary>
/// <param name="libraryPath">Path to the stable diffusion library.</param>
/// <returns>Bool if the library loaded.</returns>
public static bool LoadNativeLibrary(string libraryPath)
=> Native.LoadNativeLibrary(libraryPath);

public IImage<ColorRGB> TextToImage(string prompt, StableDiffusionParameter parameter)
{
ObjectDisposedException.ThrowIf(_disposed, this);
Expand Down