Generate image captions using Hugging Face
Use the Hugging Face Inference API to make calls to 100,000+ Machine Learning models from Supabase Edge Functions.
We can combine Hugging Face with Supabase Storage and Database Webhooks to automatically caption for any image we upload to a storage bucket.
About Hugging Face
Hugging Face is the collaboration platform for the machine learning community.
Huggingface.js provides a convenient way to make calls to 100,000+ Machine Learning models, making it easy to incorporate AI functionality into your Supabase Edge Functions.
Setup
- Open your Supabase project dashboard or create a new project.
- Create a new bucket called
images
. - Generate TypeScript types from remote Database.
- Create a new Database table called
image_caption
.- Create
id
column of typeuuid
which referencesstorage.objects.id
. - Create a
caption
column of typetext
.
- Create
- Regenerate TypeScript types to include new
image_caption
table. - Deploy the function to Supabase:
supabase functions deploy huggingface-image-captioning
. - Create the Database Webhook in the Supabase Dashboard to trigger the
huggingface-image-captioning
function anytime a record is added to thestorage.objects
table.
Generate TypeScript types
To generate the types.ts file for the storage and public schemas, run the following command in the terminal:
Code
Find the complete code on GitHub.