

GitHub - huggingface/huggingface.js: Utilities to use the Hugging Face hub API
source link: https://github.com/huggingface/huggingface.js
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hugging Face JS libraries
This is a collection of JS libraries to interact with the Hugging Face API, with TS types included.
- @huggingface/hub: Interact with huggingface.co to create or delete repos and commit / download files
- @huggingface/inference: Use the Inference API to make calls to Machine Learning models!
With more to come, like @huggingface/endpoints
to manage your HF Endpoints!
We use modern features to avoid polyfills and dependencies, so the libraries will only work on modern browsers / Node.js >= 18 / Bun / Deno.
The libraries is still very young, please help us by opening issues!
Usage example
import { createRepo, commit } from "@huggingface/hub";
import { HfInference } from "@huggingface/inference";
const HF_ACCESS_TOKEN = "hf_...";
await createRepo({
repo: {type: "model", name: "my-user/nlp-test"},
credentials: {accessToken: HF_ACCESS_TOKEN}
});
await commit({
repo: {type: "model", name: "my-user/nlp-test"},
credentials: {accessToken: HF_ACCESS_TOKEN},
title: "Add model file",
operations: [{
operation: "addOrUpdate",
path: "pytorch_model.bin",
content: new Blob(...) // Can work with native File in browsers
}]
});
const inference = new HfInference(HF_ACCESS_TOKEN);
await inference.translation({
model: 't5-base',
inputs: 'My name is Wolfgang and I live in Berlin'
})
await inference.textToImage({
inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]',
negative_prompt: 'blurry',
model: 'stabilityai/stable-diffusion-2',
})
There are more features of course, check each library's README!
Formatting & testing
pnpm install
pnpm -r format
pnpm -r test
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK