Build an AI Anyting

Hosenur published this article 09/24/2023

It's 2023, you open Twitter, get overwhelmed by the number of people building AI-[What Not], you open YouTube, and then get a frenzy of Best AI Projects of this Week videos. You also see screenshots of the developer's billing dashboard, where they show off their $100K income from the AI Side project they created. Multiple pretty cool projects emerged: AI voice cloner, AI logo designer, AI room designer, AI face cloner, AI chatbots, AI code completion, and what not!

But there was one issue with all of the projects: as AI and ML are resource-intensive technologies, all of the services were based on a freemium model, where you could get 3 or 5 generations, then you had to buy credits to get more generations. Very popular services like NightCafe, Midjourney and a lot more used this model, and to be worse, some services didn't even provide a free tier. I don't want to spend a dollar generating icons for 7 projects I create in a week, hoping to complete one day and get 5 stars on GitHub, so I thought let's solve this problem and create a project out of it. (Pretty clever, and I know it.), But building such a project should not be easy right? training models, Artifical Intelligence ? , Let's use a service which will do all the heavy lifting for use, use open source ML models and we utilize all of it trough simple APIs and SDKs.

To accomplish this, we are going to use Replicate. Replicate lets you run machine learning models with a few lines of code without needing to understand how machine learning works. Of course, it is a paid service, but you only pay for what you use, and you can use anything. Replicate provides ML models of almost everything you could ever need, like voice cloning, chat completion, image generation, logo generation, code completion, and much more

Using any Replicate model is very straightforward. Set up your billing, use the SDK of your choice, and here is the universal syntax for running a model in NodeJS.

First install the required packages and then set the ENV variables.

npm install replicate
echo REPLICATE_API_TOKEN=r8_ofcthisisnotarealapikey > .env
import Replicate from "replicate";
 
const replicate = new Replicate({
  auth: process.env.REPLICATE_API_TOKEN,
});
 
const model = "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf";
const input = { prompt: "an astronaut riding a horse on mars, hd, dramatic lighting, detailed" };
const output = await replicate.run(model, { input });
 
console.log(output);

The above snippet outputs something like this Astro boi

You are free to play around with the models, and your creativity becomes the limit on what model to use and how to use it, here are some of the highest run models along with the use case

I hope you got the AI part of the blog, now the anything part is upto you.