Prerequisites

Setup

  1. Add the Hugging Face API token to your environment variables
.env
HUGGINGFACE_API_KEY=your-api-key
  1. The boilerplate already includes the necessary configuration for Hugging Face in src/lib/ai/huggingface.ts. This file initializes the Hugging Face client with your API token.

Usage

To use Hugging Face AI in your application, you can create an API route that interacts with the Hugging Face client. This route can be used to generate images, text, and more using the AI models provided by Hugging Face. Create a new file in your API routes directory (e.g., app/api/huggingface/route.ts). You can use the Hugging Face client to interact with the AI models and generate the desired output. Here’s an example of how to set up a route that uses the Llama 3.2 1B model to generate text:

This route uses the textGeneration method from the Hugging Face client to generate text using the Llama model. You can replace the model and inputs with your desired model and prompt.

Model Selection

Hugging Face offers a wide range of AI models that you can use in your application. You can explore the available models on the Hugging Face website.