Introduction to the 🤗 Accelerated Inference API in Svelte
Hugging Face is the easiest way to build, train, and deploy machine learning models. They have done some amazing work in NLP and making Machine Learning more accessible. If you haven't heard of them, check out Spaces to see some of the awesome ML apps the community has made.
This tutorial is a quick intro to using Hugging Face's Inference API.
Every request has to have a Model and a Prompt. The API Token is optional, but it runs quicker with one, and lets you use a private model.
Each Model has its own endpoint, but
the base URL is:
https://api-inference.huggingface.co/models.
The GPT2 Model endpoint would be:
https://api-inference.huggingface.co/models/gpt2.
Different models will use different JSON inputs/outputs. The demo below makes a simple POST request from the client, but in production you would want to put the call to Hugging Face from an endpoint. Svelte has a handy await block that allows you to wait for async data directly in your markup.
Demo Time
Next Steps
Text Generation is just one use case for the API. It can also be used for Text Classification, Feature Extraction, Table Question Answering, Summarization, and more. Check out the Hugging Face course to go deeper into NLP.
More Reading
- API Infrence Docs
- Hugging Face Models
- Spaces
- Hugging Face on Sage Maker
- SvelteKit Endpoints
- SvelteKit Endpoint Video
- Svelte Await