This is the source code of SnapStager.com, a SaaS to do Virtual Staging with AI. Feel free to play around with and use the code in your project.
It uses a custom ML model called hosted on replicate similar to Stable Diffusion Inpainting. SnapStager gives you the ability to upload a photo of any room, mask the room in the web using canvas, then send both the original Image and Mask through the ML Model using a Next.js API route, and return your staged room.
Tech stack used for this app are:
- Replicate to host the ML Model
- Supabase to host the DB and Auth
- Cloudflare to host and serve both the original and final image.
- Vercel to host the NextJS App
- Prisma for the ORM
- Stripe to handle payments
Check presentation video if you want to see how to use.
git clone https://github.com/robertwt7/snapstager.git
Copy env.example
to .env
at the root of the project to start filling in the API keys
- Go to Replicate to make an account.
- Click on your profile picture in the top left corner, and click on "API Tokens".
- Here you can find your API token. Copy it.
- Store it in the .env file
- Go to Supabase
- Create a new organisation and project.
- Go to "Project Settings" at the bottom left, click on "API" under configuration
- Copy the URL and anon key under Project API Keys.
- Store it in the .env file
Next you need to store the database env which is located at prisma/env.example
, copy this file to prisma/.env
- Go to "Project Settings" at the bottom left, click on "Database" under configuration
- Copy the connection string for the Session mode ending with port
:5432
to theDIRECT_URL
env - Copy the connection string for the Transaction mode ending with port
:6543
to theDATABASE_URL
env, then add this query param at the end of the connection string:?pgbouncer=true&connection_limit=1
- Open your db in the DB Client like Dbeaver, open Databases, create a new database with the name
shadow_postgres
as the shadow db for prisma - Repeat step 2 for the
SHADOW_DATABASE_URL
and change the db after5432/postgres
to5432/shadow_postgres
- Go to Cloudflare and create an account
- Login to dashboard
- Go to "Images" at the sidebar, then click "Overview" (you have to subscribe for this)
- Copy the "Account ID" on the right and add it to the environment file under
CLOUDFLARE_ACCOUNT_ID
- Click Use API and click get API Token
- Create a new one and copy it to the environment file under
CLOUDFLARE_TOKEN
- Go to Stripe
- Create an account
- Follow the guide to create a product catalogue
- Go to each product and copy the ID at the top right to each environment var that starts with
STRIPE_PRICE_ID_<YOUR-VARIANT>
- Finally click "Developers" on the top right menu, then find your API key and create a webhook key with the correct endpoint at
https://yourdomain.com/api/stripe-webhook
and copy it to the environment file.
yarn
Then, run the application in the command line and it will be available at http://localhost:3000
.
yarn dev
This repo is MIT licensed.