AI generated room designs
Tags: ai, nextjs, openai
Published: 2023-03-05 18:32:17

As AI becomes more accessible to every developer, we will continue to see the use cases for it expand. For example, when designing a new landing page or product, I use Tailwind, but what if you could apply Tailwind to your bedroom? 

Well, you can now. 

@nutlope gifted us another AI project example, [RoomGPT](https://www.roomgpt.io/).

{% tweet 1632066593554325504 %}

_header image was generated using [midjourney](https://www.midjourney.com/app/jobs/69b517e8-e988-48b1-9367-39b20d7a9336/)_

## What is Nutlope/roomGPT?
This project dreams up designs of your room using AI. 

It uses an ML model called [ControlNet](https://github.com/lllyasviel/ControlNet) to generate variations of rooms. This application allows you to upload a photo of any room, which will be sent through this ML Model using a Next.js API route, and return your generated room.

{% github Nutlope/roomGPT noreadme %}

## How does it work?
The ML Model is hosted on [Replicate](https://replicate.com/) and [Upload](https://upload.io/) is used for image storage. During my [9 days of OpenAI series](https://dev.to/bdougieyo/30-days-of-openai-1ek6), I have focused on OpenAI, but in this example, the developer uses Replicate.

The project uses Next.js, and the AI power is in the [api/generate.ts](https://github.com/Nutlope/roomGPT/blob/main/pages/api/generate.ts) file. Similar to OpenAI, there is an API endpoint from Replicate. 

Replicate lets you run machine learning models with a cloud API without having to understand machine learning or manage infrastructure. You can run open-source models others have published or package and publish your own. Those models can be public or private. The nice part is a lot of them are open-source on GitHub, which makes it helpful for learning.

_[Explore some hosted replicate cogs](https://replicate.com/explore)_

The predictions endpoints take id, which in this example is pointed to the hosted version of [ControlNet](https://replicate.com/jagilley/controlnet/api) model. 

You can get an idea of how the prompt is being passed from the UI by taking a look at the default Game Room prompt.  

```js
// pages/api/generate.ts

  const {
  imageUrl,
  theme,
  room
} = req.body;
// POST request to Replicate to start the image restoration generation process
let startResponse = await fetch("https://api.replicate.com/v1/predictions", { // predictions
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Token " + process.env.REPLICATE_API_KEY,
  },
  body: JSON.stringify({
    version: "854e8727697a057c525cdb45ab037f64ecca770a1769cc52287c2e56472a247b", // Controlnet version
    input: {
      image: imageUrl,
      prompt: room === "Gaming Room" ?
        "a room for gaming with gaming computers, gaming consoles, and gaming chairs" :
        `a ${theme.toLowerCase()} ${room.toLowerCase()}`,
      a_prompt: "best quality, extremely detailed, photo from Pinterest, interior, cinematic photo, ultra-detailed, ultra-realistic, award-winning",
      n_prompt: "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
    },
  }),
});
```
## OpenAI vs Replicate
I am making this comparison because I had the question instantly after looking at the code. 

After a brief look at projects using both APIs, my takeaway is that Replicate gives a more straightforward developer experience through the API. OpenAI provides an experience you can fine-tune if you know want you to. Replicate allows you to run models without having to understand the intricacies of machine learning or manage your infrastructure. OpenAI doesn't require expert knowledge of machine learning, but it allows those with the ability to fine-tune models.  

If I need to correct something, or if you have some insight into the code, please comment. I enjoyed walking through the code and learning how this works. Thanks to Nutlope for sharing this with us, and be sure to contribute back upstream. Open Source FTW!

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](https://dev.to/bdougieyo/30-days-of-openai-1ek6).

_Find more AI projects using [OpenSauced](https://insights.opensauced.pizza/ai/repositories/filter/recent)_

Also, check out my bedroom redesign.

![bdougie minimlist bedroom](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygv8bil3pjic099vb9gu.png)

Stay saucy.