Skip to content

Latest commit

 

History

History
83 lines (57 loc) · 1.8 KB

README.md

File metadata and controls

83 lines (57 loc) · 1.8 KB

HuggingfaceHub Badge

A library to download models & files from HuggingFace with C#.

Key features

  • Download single file.
  • Get information of file and repo.
  • Download snapshot (repo).
  • Resume download.
  • Parallel download multiple files (only in .NET 6 or higher).
  • Upload files.
  • Support repo types other than model.

Installation

PM> Install-Package HuggingfaceHub

or

dotnet add package <your_project> HuggingfaceHub

or search HuggingfaceHub in the nuget manager tool of Visual Studio.

Usage

Download single file

using Huggingface;
var path = await HFDownloader.DownloadFileAsync("<RepoId>", "<Filename>");

Download repo

using Huggingface;
var res = await HFDownloader.DownloadSnapshotAsync("<RepoId>");

Get repo information

Currently, only model-type repo is supported.

using Huggingface;
var info = await HFDownloader.GetModelInfoAsync("<RepoId>");

Download the repo with progress handler

using Huggingface;
var res = await HFDownloader.DownloadSnapshotAsync("<RepoId>", progress: new MyConsoleProgress());

class MyConsoleProgress: IGroupedProgress
{
    public void Report(string filename, int progress)
    {
        // Do your work here. 
        // `progress` is in range [0, 100].
    }
}

Customize the endpoint

using Huggingface;
HFGlobalConfig.EndPoint = "<Endpoint Url>";

Please check the definition of HFGlobalConfig to see all the configuration you could set.

Acknowledgement

This library is mainly adopts from huggingface_hub, which is the official implementation written in Python.