Files
2025-05-28 09:55:51 +08:00

1.8 KiB

Image Captioning with Supabase Storage and Huggingface.js

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.

Putting this together with Supabase Storage and Database Webhooks we can easily put together a service that automatically generates captions for any image we upload to a storage bucket.

Setup

  1. Open your Supabase project dashboard or create a new project.
  2. Create a new bucket called images.
  3. Generate TypeScript types from remote Database.
  4. Create a new Database table called image_caption.
  • Create id column of type uuid which references storage.objects.id.
  • Create a caption column of type text.
  1. Regenerate TypeScript types to include new image_caption table.
  2. Deploy the function to Supabase: supabase functions deploy huggingface-image-captioning.
  3. Create the Database Webhook in the Supabase Dashboard to trigger the huggingface-image-captioning function anytime a record is added to the storage.objects table.

Generate TypeScript Types

To generate the types.ts file for the storage and public schemas, run the following command in the terminal:

supabase gen types typescript --project-id=your-project-ref --schema=storage,public > supabase/functions/huggingface-image-captioning/types.ts