mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Docs update ## What is the current behavior? There's no page covering the breaking changes between Supabase CLI v2 and v3. v3.0.0 was released on 2026-11-02. ## What is the new behavior? Adds a migration guide at `/docs/guides/local-development/cli/migrating-to-v3`, linked from the Local Dev / CLI nav just under "Install and run the CLI". It's modelled on [Vite's migration guide](https://vite.dev/guide/migration): a short summary, what to do before upgrading, how to install (or stay on v2), a CI quick-reference table, then one section per change, ending with the removed commands, flags, config keys and env vars as tables. The content comes from the `BREAKING CHANGE` footers of the breaking PRs on supabase/cli `next`, checked against the code there: supabase/cli#6609, supabase/cli#7064, supabase/cli#7066, supabase/cli#7074, supabase/cli#7109, supabase/cli#7116, supabase/cli#7172, supabase/cli#7176, supabase/cli#7188 and supabase/cli#7221. ## Additional context The page describes v3.0.0 as released: npm `latest`, Homebrew, Scoop and the Linux packages all install v3. The "Staying on v2" channels are live with v2.122.1: npm `v2.stable`, `supabase/tap/supabase@2`, `supabase-v2-stable` on Scoop, and `version: v2.stable` or a semver range like `^2` on `supabase/setup-cli@v3` (ranges need v3.2.0). It also updates about 60 existing guides and troubleshooting pages for v3. Hosted examples pass `--remote`, CI examples that change a hosted project pass `--yes`, deprecated target flags and removed commands are replaced, and pages that described migra as the default now describe pg-delta. It adds a new concept page, "Running commands against local and hosted projects" at `/docs/guides/local-development/local-and-hosted-projects`, linked from the Local Dev nav after "Local development workflow". It covers how a command picks its target (local by default, `--remote` and its forms, the linked project, the `Target:` line), how settings resolve (flag, then shell env, then project env files, then config), and when the CLI asks before changing a hosted project (`--yes`, `SUPABASE_YES`, `--dry-run`, seeding), with a CI recipe and a section for AI coding agents. The migration guide links to it from its target, consent and config sections. Tracks CLI-2747 🤖 Generated with [Claude Code](https://claude.com/claude-code)
93 lines
3.8 KiB
Plaintext
93 lines
3.8 KiB
Plaintext
---
|
|
title: 'Generate image captions using Hugging Face'
|
|
description: 'Use the Hugging Face Inference API to make calls to 100,000+ Machine Learning models from Supabase Edge Functions.'
|
|
subtitle: 'Use the Hugging Face Inference API to make calls to 100,000+ Machine Learning models from Supabase Edge Functions.'
|
|
video: 'https://www.youtube.com/v/OgnYxRkxEUw'
|
|
tocVideo: 'OgnYxRkxEUw'
|
|
---
|
|
|
|
We can combine Hugging Face with [Supabase Storage](/storage) and [Database Webhooks](/docs/guides/database/webhooks) to automatically caption for any image we upload to a storage bucket.
|
|
|
|
## About Hugging Face
|
|
|
|
[Hugging Face](https://huggingface.co/) is the collaboration platform for the machine learning community.
|
|
|
|
[Huggingface.js](https://huggingface.co/docs/huggingface.js/index) 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](/edge-functions).
|
|
|
|
## Setup
|
|
|
|
- Open your Supabase project dashboard or [create a new project](/dashboard/projects).
|
|
- [Create a new bucket](/dashboard/project/_/storage/buckets) called `images`.
|
|
- Generate TypeScript types from remote Database.
|
|
- 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`.
|
|
- 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](/dashboard/project/_/integrations/webhooks/overview) 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:
|
|
|
|
```bash
|
|
supabase gen types typescript --remote=your-project-ref --schema=storage,public > supabase/functions/huggingface-image-captioning/types.ts
|
|
```
|
|
|
|
## Code
|
|
|
|
Find the complete code on [GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/huggingface-image-captioning).
|
|
|
|
```ts
|
|
import { HfInference } from 'https://esm.sh/@huggingface/inference@2.3.2'
|
|
import { createClient } from 'npm:@supabase/supabase-js@2'
|
|
|
|
import { Database } from './types.ts'
|
|
|
|
console.log('Hello from `huggingface-image-captioning` function!')
|
|
|
|
const hf = new HfInference(Deno.env.get('HUGGINGFACE_ACCESS_TOKEN'))
|
|
|
|
type SoRecord = Database['storage']['Tables']['objects']['Row']
|
|
interface WebhookPayload {
|
|
type: 'INSERT' | 'UPDATE' | 'DELETE'
|
|
table: string
|
|
record: SoRecord
|
|
schema: 'public'
|
|
old_record: null | SoRecord
|
|
}
|
|
|
|
Deno.serve(async (req) => {
|
|
const payload: WebhookPayload = await req.json()
|
|
const soRecord = payload.record
|
|
const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)
|
|
const supabaseAdminClient = createClient<Database>(
|
|
// Supabase API URL - env var exported by default when deployed.
|
|
Deno.env.get('SUPABASE_URL') ?? '',
|
|
// Supabase API SECRET KEY - env var exported by default when deployed.
|
|
SUPABASE_SECRET_KEYS['default'] ?? ''
|
|
)
|
|
|
|
// Construct image url from storage
|
|
const { data, error } = await supabaseAdminClient.storage
|
|
.from(soRecord.bucket_id!)
|
|
.createSignedUrl(soRecord.path_tokens!.join('/'), 60)
|
|
if (error) throw error
|
|
const { signedUrl } = data
|
|
|
|
// Run image captioning with Huggingface
|
|
const imgDesc = await hf.imageToText({
|
|
data: await (await fetch(signedUrl)).blob(),
|
|
model: 'nlpconnect/vit-gpt2-image-captioning',
|
|
})
|
|
|
|
// Store image caption in Database table
|
|
await supabaseAdminClient
|
|
.from('image_caption')
|
|
.insert({ id: soRecord.id!, caption: imgDesc.generated_text })
|
|
.throwOnError()
|
|
|
|
return new Response('ok')
|
|
})
|
|
```
|