SmartAICompendium.Common 1.1.0

dotnet add package SmartAICompendium.Common --version 1.1.0
NuGet\Install-Package SmartAICompendium.Common -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SmartAICompendium.Common" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SmartAICompendium.Common --version 1.1.0
#r "nuget: SmartAICompendium.Common, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SmartAICompendium.Common as a Cake Addin
#addin nuget:?package=SmartAICompendium.Common&version=1.1.0

// Install SmartAICompendium.Common as a Cake Tool
#tool nuget:?package=SmartAICompendium.Common&version=1.1.0

This package contain an embedded python 3 for pythonnet and utilities for Huggingface and Civitai. Compatible with windows, linux and mac.

Usage examples

Embedded python

var dependencies = new string[] { "scipy==1.12.0", "numpy"};

EmbedPython.Initialize();

if(!EmbedPython.HasModules(dependencies))
{
    EmbedPython.PipInstall(dependencies);
}

using (Py.GIL())
{
    dynamic io = Py.Import("io");
    dynamic np = Py.Import("numpy");

    dynamic wavfile = Py.Import("scipy.io.wavfile");
    var audiofile = io.BytesIO();
    wavfile.write(audiofile, sampleRate, np.array(audio));
    return audiofile.getvalue();
}

EmbedPython.Shutdown(); //release ressources held by the python runtime if you don't intend to use it often.

EmbedPython.Clear(); //delete python files and modules installed in the app directory if you don't intend to use it again and want to keep the app light

Huggingface

EmbedPython.Initialize();
HuggingfaceHelper.Initialize();
HuggingfaceHelper.ChangeCacheFolder(".");

if(!HuggingfaceHelper.IsModelDownloaded("meta-llama/Llama-2-7b-chat-hf"))
{
    HuggingfaceHelper.DownloadModel("meta-llama/Llama-2-7b-chat-hf");
}

HuggingfaceHelper.ClearCache();

Civitai

CivitaiHelper.ChangeCacheFolder(".");

var results = CivitaiHelper.SearchModels("fantasy", limit: 10, page: 1, nfsw: false, type: CivitaiType.Checkpoint);

var firstResult = results.Items.First();
var lastVersionNumber = firstResult.ModelVersions.MaxBy(x => x.CreatedAt);

string path;
if(CivitaiHelper.IsModelDownloaded(lastVersionNumber.Id))
{
    path = CivitaiHelper.GetModelFilePath(lastVersionNumber.Id);
}
else
{
    path = CivitaiHelper.DownloadModel(lastVersionNumber.Id);
}

CivitaiHelper.GetModelInfos(lastVersionNumber.Id);

CivitaiHelper.ClearCache();

Support My work

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on SmartAICompendium.Common:

Package Downloads
SmartAICompendium.ImageGeneration

Image generation with local models

SmartAICompendium.AudioGeneration

Audio generation with local models

SmartAICompendium.TextGeneration

Text generation with local models

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 301 2/1/2024
1.0.2 117 1/30/2024
1.0.1 92 1/30/2024
1.0.0 118 1/30/2024