DEV Community

Cover image for AI powered age transformation
Brian Douglas
Brian Douglas

Posted on • Updated on

AI powered age transformation

The AI-powered photo-aging project's premise is either fun or highly morbid. Developer, @steventey, put together Extrapolate, a project that lets you see how well you will age using AI.

Perhaps you are not on TikTok, but there is a TikTok filter that makes GenX users cry. You can see it here on YouTube. Extrapolate is the reverse of letting GenZ reduce FOMO and see what they look like old (joking).

header image was generated using midjourney

GitHub logo steven-tey / extrapolate

Age transformation AI app powered by Next.js, Vercel, Replicate, Upstash, and Cloudflare R2 + Workers.

What is steven-tey/extrapolate?

How will you look in 10 years? 20 years? When you're 90? Upload a photo to extrapolate.app to find out. It is free and privacy-friendly because all images are deleted after 24 hours.

extrapolate example gif

How does it work?

As I have done previously in the 9 days of OpenAI series, I walk through the AI code and talk through how it works.

Similar to how the AI generated room designs was built, Extrapolate leverages Replicate.

The model number is referenced in the code is "9222a21c181b707209ef12b5e0d7e94c994b58f01c7b2fec075d2e892362f13c", but there it does seem to be private or not searchable. If someone more familiar with Replicate wants to tell if I am wrong on this, please comment.

Hosted models' privacy is an exciting feature for Replicate, considering not all models need to be discoverable. If I choose to build my own, I am even more intrigued about using Replicate to store my future models.

I searched for other models that age photos and found the model named Sam to be pretty close.

search on replicate for aging

But looking at the code, you can see the fetch call to the replicate predictions endpoint from the pages/api/upload.ts.



// pages/api/upload.ts

fetch("https://api.replicate.com/v1/predictions", {
  method: "POST",
  headers: {
    "Content-Type": "application/JSON",
    Authorization: "Token " + process.env.REPLICATE_API_KEY,
  },
  body: JSON.stringify({
    version: "9222a21c181b707209ef12b5e0d7e94c994b58f01c7b2fec075d2e892362f13c", // model version
    input: {
      image,
      target_age: "default",
    },
    webhook_completed: `${domain}/api/images/${key}/webhook?token=${process.env.REPLICATE_WEBHOOK_TOKEN}`,
  }),
}).then((res) => res.json()),

...


Enter fullscreen mode Exit fullscreen mode

I was also curious about the 24hr photo deletion and which is referenced in the README. It appears to be handled by a service provided by Upstash (Serverless Data for Redis), and runs on a schedule using a tool called Qstash. Qstash is new to me, but it's a message queue and task scheduler designed for serverless runtimes (In this example, Cloudflare workers).

I had not seen the Cloudflare R2 product in the wild prior. It provides similar unstructured bucket storage as S3 and is used for quick uploads. This work happens in the pages/api/images/[id]/delete.ts file.

Below is the code that manages the deletion, which is called on schedule.



// pages/API/images/[id]/delete.ts
...
await Promise.allSettled([
  fetch(`https://images.extrapolate.workers.dev/${id}`, {
    method: "DELETE",
    headers: {
      "X-CF-Secret": process.env.CLOUDFLARE_WORKER_SECRET as string,
    },
  }),
  redis.set(id, {
    expired: true,
  }),
]);


Enter fullscreen mode Exit fullscreen mode

My takeaway from this implementation is that the AI interaction is abstracted away by Replicate. If you are a developer looking to ship a project leveraging AI quickly, this is an excellent project to dig deeper into.

Today, Vercel did announce several AI starter kits, including the one we just looked at. I plan to cover the rest of the list. Take a look if you want to deploy and yry a project today.

Also, if you have a project leveraging OpenAI or similar, leave a link in the comments. I'd love to take a look and include it in my 9 days of OpenAI series.

Find more AI projects using OpenSauced

Stay saucy.

Top comments (0)