forked from Nutlope/roomGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REPLICATE_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
# Next.js + Tailwind CSS Example | ||
# RestorePhotos.io | ||
|
||
This example shows how to use [Tailwind CSS](https://tailwindcss.com/) [(v3.2)](https://tailwindcss.com/blog/tailwindcss-v3-2) with Next.js. It follows the steps outlined in the official [Tailwind docs](https://tailwindcss.com/docs/guides/nextjs). | ||
A service that will restore old face photos. | ||
|
||
## Deploy your own | ||
## Todos | ||
|
||
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-tailwindcss) | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss&project-name=with-tailwindcss&repository-name=with-tailwindcss) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example with-tailwindcss with-tailwindcss-app | ||
``` | ||
|
||
```bash | ||
yarn create next-app --example with-tailwindcss with-tailwindcss-app | ||
``` | ||
|
||
```bash | ||
pnpm create next-app --example with-tailwindcss with-tailwindcss-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). | ||
- [ ] Get initial API route to work | ||
- [ ] Figure how to feed API an image from the UI | ||
- [ ] Create the UI for uploading an image | ||
- [ ] Get an OG card |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
type Data = string; | ||
interface ExtendedNextApiRequest extends NextApiRequest { | ||
body: { | ||
imageUrl: string; | ||
}; | ||
} | ||
|
||
export default async function handler(req: ExtendedNextApiRequest, res: NextApiResponse<Data>) { | ||
const { imageUrl } = req.query; | ||
// POST request to Replicate to start the image restoration generation process | ||
let startResponse = await 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: "9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3", | ||
input: { img: imageUrl, version: "v1.4", scale: 2 }, | ||
}), | ||
}); | ||
|
||
let jsonStartResponse = await startResponse.json(); | ||
let endpointUrl = jsonStartResponse.urls.get; | ||
|
||
// GET request to get the status of the image restoration process & return the result when it's ready | ||
let restoredImage: string | null = null; | ||
while (!restoredImage) { | ||
// Loop in 1s intervals until the alt text is ready | ||
let finalResponse = await fetch(endpointUrl, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Token " + process.env.REPLICATE_API_KEY, | ||
}, | ||
}); | ||
let jsonFinalResponse = await finalResponse.json(); | ||
|
||
if (jsonFinalResponse.status === "succeeded") { | ||
restoredImage = jsonFinalResponse.output; | ||
} else if (jsonFinalResponse.status === "failed") { | ||
break; | ||
} else { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
} | ||
res.status(200).json(restoredImage ? restoredImage : "Failed to restore image"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters