Skip to content

Commit 956cc01

Browse files
committed
docs: article ready
1 parent d97a568 commit 956cc01

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

docs/content/0.index.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ hero:
1010
light: '/images/landing/hero-light.svg'
1111
dark: '/images/landing/hero-dark.svg'
1212
headline:
13-
label: NuxtHub AI is out
14-
to: /changelog/hub-ai
13+
label: Using AI for User Experience
14+
to: /blog/cloudflare-ai-for-user-experience
1515
icon: i-ph-arrow-right
1616
links:
1717
- label: Get started

docs/content/5.blog/3.cloudflare-ai-for-user-experience.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ authors:
1010
username: atinux
1111
date: 2024-08-26
1212
category: Tutorial
13-
draft: true
1413
---
1514

1615
## Introduction
1716

1817
Let's improve [Atidraw](https://github.com/atinux/atidraw), an open source collaborative drawing app made with Nuxt.
1918

2019
The application has basic features such as:
21-
- Auth with Google, GitHub or Anonymously based on [`nuxt-auth-utils`](https://github.com/Atinux/nuxt-auth-utils)
22-
- Draw with [`signature_pad`](https://github.com/szimek/signature_pad)
20+
- Authentication with Google, GitHub or login anonymously based on [`nuxt-auth-utils`](https://github.com/Atinux/nuxt-auth-utils)
21+
- Drawing with [`signature_pad`](https://github.com/szimek/signature_pad)
2322
- Upload and store drawings with Cloudflare R2 using [`hubBlob()`](/docs/features/blob)
2423

2524
You can play with it on [draw.nuxt.dev](https://draw.nuxt.dev).
@@ -34,7 +33,7 @@ This is important to know how Cloudflare AI models are billed.
3433

3534
Cloudflare free allocation allows anyone to use a total of 10,000 Neurons per day at no charge.
3635

37-
Neurons are Cloudflare way of measuring AI outputs across different models. To give you a sense of what you can accomplish with 10,000 Neurons, you can generate:
36+
Neurons are Cloudflare's way of measuring AI outputs across different models. To give you a sense of what you can accomplish with 10,000 Neurons, you can generate one of the following (or an equivalent mix):
3837
- 100-200 LLM responses
3938
- 500 translations
4039
- 500 seconds of speech-to-text audio
@@ -53,7 +52,7 @@ Read more about **Cloudflare AI pricing**.
5352

5453
## Add AI to Nuxt
5554

56-
To add AI to our Nuxt application, we need to enable the AI feature on our `nuxt.config.ts` file.
55+
To add AI to our Nuxt application, we need to enable the AI feature in our `nuxt.config.ts` file.
5756

5857
```ts [nuxt.config.ts]
5958
export default defineNuxtConfig({
@@ -78,17 +77,17 @@ This will allow the module to call AI models from your linked Cloudflare account
7877
That's it! We can now use the AI models from Cloudflare using [`hubAI()`](/docs/features/ai).
7978
::
8079

81-
I've been thinking on two features:
80+
I've been thinking about two features:
8281
- Generate the alternative text for the user drawings, improving the accessibility of the application & SEO.
83-
- Generate an image based from the drawing and the alternative text, as a way to make the application more interactive.
82+
- Generate an image based on the drawing and the alternative text, as a way to make the application more interactive.
8483

8584
Before starting, I took a look at [Cloudflare's multi modal playground](https://multi-modal.ai.cloudflare.com/) and played with some models.
8685

8786
:nuxt-img{alt="Atidraw AI models" dataZoomSrc="/images/blog/atidraw-ai-models.png" height="515" src="/images/blog/atidraw-ai-models.png" width="915"}
8887

8988
This guided me to the following models:
90-
- [LLaVA](https://developers.cloudflare.com/workers-ai/models/llava-1.5-7b-hf/) for the alternative text
91-
- [Stable Diffusion IMG2IMG](https://developers.cloudflare.com/workers-ai/models/stable-diffusion-v1-5-img2img/) for the alternative drawing
89+
- [LLaVA](https://developers.cloudflare.com/workers-ai/models/llava-1.5-7b-hf/) for the alternative text generation
90+
- [Stable Diffusion IMG2IMG](https://developers.cloudflare.com/workers-ai/models/stable-diffusion-v1-5-img2img/) for the alternative drawing generation
9291

9392
::note{to="https://developers.cloudflare.com/workers-ai/models/" target="_blank"}
9493
See all **Cloudflare AI models** available.
@@ -205,11 +204,11 @@ await hubAI().run('@cf/runwayml/stable-diffusion-v1-5-img2img', {
205204

206205
It takes the following inputs:
207206
- `image` (as `Uint8Array`) to use as a reference for the image generation
208-
- `prompt` to guides the model in generating the image
207+
- `prompt` to guide the model in generating the image
209208
- `guidance` to control how closely the generated image adheres to the given text prompt
210-
- `strength` to controls how much the model changes the input image, with higher values creating bigger changes.
209+
- `strength` to control how much the model changes the input image, with higher values creating bigger changes.
211210

212-
Let's update our `/api/upload` route to generate the alternative drawing and store it in the R2 bucket.
211+
Let's update our `/api/upload` route to generate the alternative drawing and store it our R2 bucket.
213212

214213
```ts [server/api/upload.post.ts]
215214
export default eventHandler(async (event) => {
@@ -245,9 +244,9 @@ export default eventHandler(async (event) => {
245244
})
246245
```
247246

248-
As you can see, we store the pathname of the AI generated image in the custom metadata of the drawing.
247+
As you can see, we store the `pathname` of the AI generated image in the custom metadata of the drawing.
249248

250-
Now, we can display the AI generated image in the listing page when hovering the user's drawing:
249+
Now, we can display the AI generated image in our listing page when hovering the user's drawing:
251250

252251
```vue [app/pages/index.vue]
253252
<script setup lang="ts">
@@ -290,12 +289,12 @@ I am quite happy with the result:
290289
::
291290

292291
::note
293-
Sometime the AI generated image is black, this is because the model is not able to generate an image from the description, most of the time because it is a sensitive content or misunderstood the description.
292+
Sometimes the AI generated image is black, this is because the model is not able to generate an image from the description, most of the time because it is sensitive content or it misunderstood the description.
294293
::
295294

296295
## Conclusion
297296

298-
This is the end of this tutorial on how to use Cloudflare AI models in a Nuxt application. I hope you enjoyed it and that it gave you some ideas on how to use AI in your Nuxt application.
297+
This is the end of this tutorial on how to use Cloudflare AI models in a Nuxt application. I hope you enjoyed it and that it gave you some ideas on how to use AI for improving accessibility, SEO or User Experience.
299298

300299
Feel free to expand on this foundation and add your own unique features to make Atidraw yours!
301300

0 commit comments

Comments
 (0)