Gathering detailed insights and metrics for @huggingface/hub
Gathering detailed insights and metrics for @huggingface/hub
Gathering detailed insights and metrics for @huggingface/hub
Gathering detailed insights and metrics for @huggingface/hub
npm install @huggingface/hub
Typescript
Module System
Min. Node Version
Node Version
NPM Version
63
Supply Chain
99.3
Quality
94.6
Maintenance
100
Vulnerability
100
License
TypeScript (71.24%)
Svelte (16.4%)
JavaScript (11.59%)
CSS (0.38%)
Python (0.25%)
Shell (0.12%)
HTML (0.03%)
Total Downloads
284,014
Last Day
371
Last Week
2,129
Last Month
16,739
Last Year
208,095
1,455 Stars
1,111 Commits
254 Forks
48 Watching
54 Branches
272 Contributors
Latest Version
1.0.0
Package Id
@huggingface/hub@1.0.0
Unpacked Size
836.51 kB
Size
186.95 kB
File Count
341
NPM Version
10.8.2
Node Version
20.18.1
Publised On
06 Dec 2024
Cumulative downloads
Total Downloads
Last day
27.9%
371
Compared to previous day
Last week
-44.1%
2,129
Compared to previous week
Last month
6.5%
16,739
Compared to previous month
Last year
174.1%
208,095
Compared to previous year
1
1
Official utilities to use the Hugging Face Hub API.
1pnpm add @huggingface/hub 2 3npm add @huggingface/hub 4 5yarn add @huggingface/hub
1// esm.sh 2import { uploadFiles, listModels } from "https://esm.sh/@huggingface/hub" 3// or npm: 4import { uploadFiles, listModels } from "npm:@huggingface/hub"
Check out the full documentation.
For some of the calls, you need to create an account and generate an access token.
Learn how to find free models using the hub package in this interactive tutorial.
1import * as hub from "@huggingface/hub"; 2import type { RepoDesignation } from "@huggingface/hub"; 3 4const repo: RepoDesignation = { type: "model", name: "myname/some-model" }; 5 6const {name: username} = await hub.whoAmI({accessToken: "hf_..."}); 7 8for await (const model of hub.listModels({search: {owner: username}, accessToken: "hf_..."})) { 9 console.log("My model:", model); 10} 11 12const specificModel = await hub.modelInfo({name: "openai-community/gpt2"}); 13await hub.checkRepoAccess({repo, accessToken: "hf_..."}); 14 15await hub.createRepo({ repo, accessToken: "hf_...", license: "mit" }); 16 17await hub.uploadFiles({ 18 repo, 19 accessToken: "hf_...", 20 files: [ 21 // path + blob content 22 { 23 path: "file.txt", 24 content: new Blob(["Hello World"]), 25 }, 26 // Local file URL 27 pathToFileURL("./pytorch-model.bin"), 28 // Web URL 29 new URL("https://huggingface.co/xlm-roberta-base/resolve/main/tokenizer.json"), 30 // Path + Web URL 31 { 32 path: "myfile.bin", 33 content: new URL("https://huggingface.co/bert-base-uncased/resolve/main/pytorch_model.bin") 34 } 35 // Can also work with native File in browsers 36 ], 37}); 38 39// or 40 41for await (const progressEvent of await hub.uploadFilesWithProgress({ 42 repo, 43 accessToken: "hf_...", 44 files: [ 45 ... 46 ], 47})) { 48 console.log(progressEvent); 49} 50 51await hub.deleteFile({repo, accessToken: "hf_...", path: "myfile.bin"}); 52 53await (await hub.downloadFile({ repo, path: "README.md" })).text(); 54 55for await (const fileInfo of hub.listFiles({repo})) { 56 console.log(fileInfo); 57} 58 59await hub.deleteRepo({ repo, accessToken: "hf_..." });
It's possible to login using OAuth ("Sign in with HF").
This will allow you get an access token to use some of the API, depending on the scopes set inside the Space or the OAuth App.
1import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub"; 2 3const oauthResult = await oauthHandleRedirectIfPresent(); 4 5if (!oauthResult) { 6 // If the user is not logged in, redirect to the login page 7 window.location.href = await oauthLoginUrl(); 8} 9 10// You can use oauthResult.accessToken, oauthResult.accessTokenExpiresAt and oauthResult.userInfo 11console.log(oauthResult);
Checkout the demo: https://huggingface.co/spaces/huggingfacejs/client-side-oauth
The @huggingface/hub
package provide basic capabilities to scan the cache directory. Learn more about Manage huggingface_hub cache-system.
scanCacheDir
You can get the list of cached repositories using the scanCacheDir
function.
1import { scanCacheDir } from "@huggingface/hub"; 2 3const result = await scanCacheDir(); 4 5console.log(result);
Note: this does not work in the browser
downloadFileToCacheDir
You can cache a file of a repository using the downloadFileToCacheDir
function.
1import { downloadFileToCacheDir } from "@huggingface/hub"; 2 3const file = await downloadFileToCacheDir({ 4 repo: 'foo/bar', 5 path: 'README.md' 6}); 7 8console.log(file);
Note: this does not work in the browser
snapshotDownload
You can download an entire repository at a given revision in the cache directory using the snapshotDownload
function.
1import { snapshotDownload } from "@huggingface/hub"; 2 3const directory = await snapshotDownload({ 4 repo: 'foo/bar', 5}); 6 7console.log(directory);
The code use internally the downloadFileToCacheDir
function.
Note: this does not work in the browser
When uploading large files, you may want to run the commit
calls inside a worker, to offload the sha256 computations.
Remote resources and local files should be passed as URL
whenever it's possible so they can be lazy loaded in chunks to reduce RAM usage. Passing a File
inside the browser's context is fine, because it natively behaves as a Blob
.
Under the hood, @huggingface/hub
uses a lazy blob implementation to load the file.
@huggingface/tasks
: Typings onlyNo vulnerabilities found.
No security vulnerabilities found.