Skip to content

Commit 5d303ce

Browse files
committed
New Realtime example added to docs
1 parent d98221b commit 5d303ce

File tree

4 files changed

+90
-12
lines changed

4 files changed

+90
-12
lines changed

docs/guides/examples/fal-ai-image-to-cartoon.mdx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
---
2-
title: "Convert an image to a cartoon using fal AI"
3-
sidebarTitle: "fal AI image to cartoon"
4-
description: "This example demonstrates how to convert an image to a cartoon using fal AI with Trigger.dev."
2+
title: "Convert an image to a cartoon using Fal.ai"
3+
sidebarTitle: "Fal.ai image to cartoon"
4+
description: "This example task generates an image from a URL using Fal.ai and uploads it to Cloudflare R2."
55
---
66

7-
## Overview
7+
## Walkthrough
88

9-
Fal AI is a platform that provides access to advanced AI models for tasks such as image generation, text summarization, and hyperparameter tuning.
9+
This video walks through the process of creating this task in a Next.js project.
10+
11+
<div className="w-full h-full aspect-video mb-3">
12+
<iframe width="100%" height="100%" src="https://www.youtube.com/embed/AyRT4X8dHK0?si=ugA172V_3TMjik9h" title="Trigger.dev walkthrough" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen/>
13+
</div>
1014

1115
## Prerequisites
1216

13-
- A project with [Trigger.dev initialized](/quick-start)
14-
- A [fal AI](https://fal.ai/) account
15-
- A [Cloudflare](https://developers.cloudflare.com/r2/) account and bucket
17+
- An existing project
18+
- A [Trigger.dev account](https://cloud.trigger.dev) with Trigger.dev [initialized in your project](/quick-start)
19+
- A [Fal.ai](https://fal.ai/) account
20+
- A [Cloudflare](https://developers.cloudflare.com/r2/) account with an R2 bucket setup
1621

1722
## Task code
1823

19-
This task converts an image to a cartoon using fal AI, and uploads the result to Cloudflare R2.
24+
This task converts an image to a cartoon using Fal.ai, and uploads the result to Cloudflare R2.
2025

2126
```ts trigger/fal-ai-image-to-cartoon.ts
2227
import { logger, task } from "@trigger.dev/sdk/v3";
@@ -27,7 +32,7 @@ import { z } from "zod";
2732

2833
// Initialize fal.ai client
2934
fal.config({
30-
credentials: process.env.FAL_KEY, // Get this from your fal AI dashboard
35+
credentials: process.env.FAL_KEY, // Get this from your fal.ai dashboard
3136
});
3237

3338
// Initialize S3-compatible client for Cloudflare R2
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "Convert an image to a cartoon using Fal.ai and Trigger.dev Realtime"
3+
sidebarTitle: "Fal.ai with Realtime"
4+
description: "This example demonstrates how to convert an image to a cartoon using Fal.ai and shows the progress of the task on the frontend using Trigger.dev Realtime."
5+
---
6+
7+
## Walkthrough
8+
9+
This video walks through the process of creating this task in a Next.js project.
10+
11+
<div className="w-full h-full aspect-video mb-3">
12+
<iframe width="100%" height="100%" src="https://www.youtube.com/embed/BWZqYfUaigg?si=XpqVUEIf1j4bsYZ4" title="Trigger.dev walkthrough" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen/>
13+
</div>
14+
15+
## Prerequisites
16+
17+
- An existing project
18+
- A [Trigger.dev account](https://cloud.trigger.dev) with Trigger.dev [initialized in your project](/quick-start)
19+
- A [Fal.ai](https://fal.ai/) account
20+
21+
## Task code
22+
23+
This task converts an image to a cartoon using fal AI, and uploads the result to Cloudflare R2.
24+
25+
```ts trigger/fal-ai-image-from-prompt-realtime.ts
26+
import * as fal from "@fal-ai/serverless-client";
27+
import { logger, schemaTask } from "@trigger.dev/sdk/v3";
28+
import { z } from "zod";
29+
30+
export const FalResult = z.object({
31+
images: z.tuple([z.object({ url: z.string() })]),
32+
});
33+
34+
export const payloadSchema = z.object({
35+
imageUrl: z.string().url(),
36+
prompt: z.string(),
37+
});
38+
39+
export const realtimeImageGeneration = schemaTask({
40+
id: "realtime-image-generation",
41+
schema: payloadSchema,
42+
run: async (payload) => {
43+
const result = await fal.subscribe("fal-ai/flux/dev/image-to-image", {
44+
input: {
45+
image_url: payload.imageUrl,
46+
prompt: payload.prompt,
47+
},
48+
onQueueUpdate: (update) => {
49+
logger.info("Fal.ai processing update", { update });
50+
},
51+
});
52+
53+
const $result = FalResult.parse(result);
54+
const [{ url: cartoonUrl }] = $result.images;
55+
56+
return {
57+
imageUrl: cartoonUrl,
58+
};
59+
},
60+
});
61+
```
62+
63+
### Testing your task
64+
65+
You can test your task by triggering it from the Trigger.dev dashboard. Here's an example payload:
66+
67+
```json
68+
{
69+
"imageUrl": "https://static.vecteezy.com/system/resources/previews/005/857/332/non_2x/funny-portrait-of-cute-corgi-dog-outdoors-free-photo.jpg",
70+
"prompt": "Dress this dog for Christmas"
71+
}
72+
```

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
"guides/examples/dall-e3-generate-image",
338338
"guides/examples/deepgram-transcribe-audio",
339339
"guides/examples/fal-ai-image-to-cartoon",
340+
"guides/examples/fal-ai-realtime",
340341
"guides/examples/ffmpeg-video-processing",
341342
"guides/examples/firecrawl-url-crawl",
342343
"guides/examples/open-ai-with-retrying",

docs/video-walkthrough.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ description: "Go from zero to a working task in your Next.js app in 10 minutes."
1111

1212
- [0:00](https://youtu.be/YH_4c0K7fGM?si=J8svVzotZtyTXDap&t=0)[Install Trigger.dev](/quick-start) in an existing Next.js project
1313
- [1:44](https://youtu.be/YH_4c0K7fGM?si=J8svVzotZtyTXDap&t=104)[Run and test](/run-tests) the "Hello, world!" example project
14-
- [2:09](https://youtu.be/YH_4c0K7fGM?si=FMTP8ep_cDBCU0_x&t=128) – Create and run an AI image generation task that uses [Fal.ai](https://fal.ai)
15-
- [6:25](https://youtu.be/YH_4c0K7fGM?si=pPc8iLI2Y9FGD3yo&t=385) – Create and run a [Trigger.dev Realtime](/realtime/overview) example using [Trigger.dev React hooks](/frontend/react-hooks)
14+
- [2:09](https://youtu.be/YH_4c0K7fGM?si=FMTP8ep_cDBCU0_x&t=128) – Create and run an AI image generation task that uses [Fal.ai](https://fal.ai) – ([View the code](/guides/examples/fal-ai-image-to-cartoon))
15+
- [6:25](https://youtu.be/YH_4c0K7fGM?si=pPc8iLI2Y9FGD3yo&t=385) – Create and run a [Realtime](/realtime/overview) example using [React hooks](/frontend/react-hooks) – ([View the code](/guides/examples/fal-ai-image-to-cartoon-realtime))
1616
- [11:10](https://youtu.be/YH_4c0K7fGM?si=Mjd0EvvNsNlVouvY&t=670)[Deploy your task](/cli-deploy) to the Trigger.dev Cloud

0 commit comments

Comments
 (0)