Giter Site home page Giter Site logo

martinsmind / huggingface.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huggingface/huggingface.js

1.0 0.0 0.0 1.21 MB

Utilities to use the Hugging Face hub API

Home Page: https://huggingface.co

License: MIT License

JavaScript 1.02% TypeScript 98.98%

huggingface.js's Introduction


huggingface javascript library logo

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 100,000+ 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 are still very young, please help us by opening issues!

Installation

From NPM

To install via NPM, you can download the libraries as needed:

npm install @huggingface/hub
npm install @huggingface/inference

Then import the libraries in your code:

import { createRepo, commit, deleteRepo, listFiles } from "@huggingface/hub";
import { HfInference } from "@huggingface/inference";
import type { RepoId, Credentials } from "@huggingface/hub";

From CDN or Static hosting

You can run our packages with vanilla JS, without any bundler, by using a CDN or static hosting. Using ES modules, i.e. <script type="module">, you can import the libraries in your code:

<script type="module">
    import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@1/+esm';
    import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0/+esm";
</script>

Usage example

import { createRepo, commit } from "@huggingface/hub";
import { HfInference } from "@huggingface/inference";

// use an access token from your free account
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

Building

pnpm -r build

This will generate ESM and CJS javascript files in packages/*/dist, eg packages/inference/dist/index.mjs.

huggingface.js's People

Contributors

coyotte508 avatar radames avatar timmikeladze avatar gary149 avatar julien-c avatar merveenoyan avatar quatton avatar pierrci avatar kakulukian avatar o-az avatar pngwn avatar

Stargazers

Nwoha Martins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.