---
layout: integration
title: Image classification with Hugging Face
description: Understand and label the contents of images
date: 2024-07-30
featured: false
isPartner: true
isNew: false
cover: /images/integrations/ai-hugging-face-image-classification/cover.avif
category: ai
product:
    avatar: '/images/integrations/avatars/hugging-face.avif'
    vendor: Hugging Face
    description: 'Hugging Face is a leading AI company that offers an extensive library of pre-trained models for various natural language processing and computer vision tasks, including image classification.'
platform:
    - 'Self-hosted'
    - 'Cloud'
images:
    - /images/integrations/ai-hugging-face-image-classification/cover.avif
    - /images/integrations/ai-hugging-face-image-classification/appwrite-functions-image-classification-hugging-face.avif
    - /images/integrations/ai-hugging-face-image-classification/appwrite-functions-image-classification-hugging-face.avif
    - /images/integrations/ai-hugging-face-image-classification/appwrite-functions-env-variables-image-classification-hugging-face.avif
---

Image classification is a key application of machine learning that involves categorizing images into predefined classes. Hugging Face is a leading AI company that offers an extensive library of pre-trained models for various natural language processing and computer vision tasks, including image classification. By integrating Hugging Face's powerful models with your applications, you can leverage state-of-the-art technology to automate and enhance image analysis.

# How does the integration work?

You can utilize a pre-built Appwrite function template to add image classification with Hugging Face to your app. This will allow you to upload an image to an Appwrite storage bucket and store labels from the image in an Appwrite collection.

# How to implement

To implement the Hugging Face image classification function, there are several steps you must complete:

## Step 1: Sign up for Hugging Face

First, you must [sign up for a Hugging Face account](https://huggingface.co/join). Once your account is set up, visit your profile settings, head to the [Access Tokens](https://huggingface.co/settings/tokens) page, and create an **access token** with the **Inference** permissions. Save this token for further usage.

![Create API token](/images/integrations/ai-hugging-face-image-classification/hugging-face-create-api-token.avif)

## Step 2: Create the Appwrite Function

For this step, you must [create an account on Appwrite Cloud](https://cloud.appwrite.io/register) or [self-host Appwrite](https://appwrite.io/docs/advanced/self-hosting) if you haven’t already. If you decide to self-host Appwrite, there are [additional setup steps](https://appwrite.io/docs/advanced/self-hosting/functions) to use Appwrite Function templates.

Head over to the Appwrite console, navigate to the **Functions** page, click on the **Templates** tab, and search for the **Image Classification** function template.

![Function template](/images/integrations/ai-hugging-face-image-classification/appwrite-functions-image-classification-hugging-face.avif)

During the setup process, click on the checkbox to generate an Appwrite API key on completion and add the **Hugging Face access token** in the **Variables** step. If you are self-hosting Appwrite, then click on the **optional variables** dropdown and update the Appwrite endpoint to your instance’s publicly accessible endpoint.

![Environment variables](/images/integrations/ai-hugging-face-image-classification/appwrite-functions-env-variables-image-classification-hugging-face.avif)

Then, create a new repository with the default branch and root directory settings. You can edit this repository later to update the function logic.

## Step 3: Test the function

Once all the steps are complete, it is time to test the function! Use the Appwrite console or one of Appwrite’s SDKs to [upload an image](https://appwrite.io/docs/references/cloud/client-web/storage#createFile) to the `image_classification` storage bucket. If successful, you will find a response saved in the `image_classification` collection in the `ai` database in the following format:

| image | labels |
| --- | --- |
| `66a13bf100318c752f1b` | `[{"label":"llama","score":0.9664694666862488},{"label":"comic book","score":0.019199883565306664},{"label":"suit, suit of clothes","score":0.005637330934405327},{"label":"television, television system","score":0.00037627643905580044},{"label":"muzzle","score":0.00019786457414738834}]` |

The `image` attribute contains the ID of the image file uploaded to the `image_classification` storage bucket, and the `labels` attribute contains the response from Hugging Face, including all the labels and their confidence score.

# Read more about Hugging Face and Appwrite Functions

If you would like to learn more about Hugging Face and Appwrite Functions, we have some resources that you should visit:

- [Sign up for Hugging Face](https://huggingface.co/login)
- [Set up the Hugging Face provider in Appwrite](https://appwrite.io/docs/products/ai/tutorials/image-classification)
- [Building with Appwrite AI Function templates](https://appwrite.io/blog/post/building-with-ai-function-templates)
- [Introducing the Python machine learning runtime](https://appwrite.io/blog/post/introducing-python-machine-learning-runtime)
- [Find more function templates](https://appwrite.io/docs/products/functions/templates)
- [Appwrite Functions API reference](https://appwrite.io/docs/references)
