DEV Community

Cover image for Image Generator with Cloudflare
Luis
Luis

Posted on • Edited on

4 1 1

Image Generator with Cloudflare

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

Demo

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

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.

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more