Skip to content

Add Image Redraw example combining multiple Cloudflare bindings - #93

Open
ryanking13 wants to merge 5 commits into
mainfrom
gyeongjae/ai-redraw
Open

Add Image Redraw example combining multiple Cloudflare bindings#93
ryanking13 wants to merge 5 commits into
mainfrom
gyeongjae/ai-redraw

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

This adds an Image Redraw example similar to something we showed in PyCon US this year.

  • FastAPI for api server
  • Pillow for image resizing
  • R2 for storing images
  • Queue for queuing jobs
  • Workflows for durable execution
  • Workers AI for img2img conversion
image

try {
rawUpload = await inspectFile(file);
previewUrl = URL.createObjectURL(rawUpload.file);
previewImage.src = previewUrl;

@dom96 dom96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, I like how many different services this shows off


@app.post("/api/jobs", status_code=202)
async def create_job(request: Request) -> dict[str, str]:
content_type = request.headers.get("content-type", "").split(";")[0].strip().lower()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any package we can use that would parse this for us in a more robust way?

)

try:
await env.REDRAW_QUEUE.send({"jobId": job_id})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of submitting this to a queue manually, I wonder if you could use R2's event notifications to show it off and streamline this code https://developers.cloudflare.com/r2/buckets/event-notifications/

)

# Magic bytes, because the model tells us nothing about the format it picked.
IMAGE_SIGNATURES = ((b"\x89PNG", "image/png"), (b"\xff\xd8\xff", "image/jpeg"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fun. Are there other formats it could generate? Webp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants