Image Generator with Cloudflare
Luis
Posted on April 11, 2024
This is a submission for the Cloudflare AI Challenge.
What I Built
Simple App for Text to Image.
In addition, image modification using img2img or inpainting models.
Demo
Web Site: https://ai-paint.luis.fun
My Code
Repository: https://github.com/LuisFun/ai-paint
License: AGPL-3.0
Journey
I had been developing an app that could generate images on a website even before the challenge started. This time, I applied because it roughly matched the entry requirements of the challenge.
During the challenge period, I worked on the following:
- Utilized Workers AI through the AI Gateway
- Enabled the enlargement of uploaded image
- Implemented the inpainting mode
Stacks
- Cloudflare
- Svelte kit
- Skeleton
-
@luisfun/cloudflare-ai-plugin
(I made it)
The two things I focused on when creating the frontend were eliminating unnecessary UI and making the UI more understandable.
What I kept in mind when creating the backend was to protect the AI-related API from bot attacks.
I achieved this using the AI Gateway and Turnstile.
AI Gateway can utilize Real-time logs, Caching, and Rate-limiting.
Turnstile determines whether it's a human or a bot, and blocks appropriately.
Multiple Models and/or Triple Task Types
@cf/lykon/dreamshaper-8-lcm
@cf/runwayml/stable-diffusion-v1-5-img2img
@cf/runwayml/stable-diffusion-v1-5-inpainting
@cf/meta/m2m100-1.2b
When the language of the Prompt is specified as something other than EN, the Prompt is first translated into English using m2m100-1.2b, and then the translated Prompt is input in image generation.
(You can select this if the default language of your browser is not EN.)
The img2img model automatically switches when an image is uploaded.
The inpainting model automatically switches when a mask is added.
P.S.
The project's code includes code to display Adsense.
Originally, considering long-term operation, it was added as one means to recover operating costs.
However, considering the submission requirements, the ads are hidden during the challenge period (throughout April).
(Apr 13) I have installed the @luisfun/cloudflare-ai-plugin
that was created in this project.
Posted on April 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.