forked from replicate/getting-started-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 935 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Replicate from "replicate";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
export default async function handler(req, res) {
if (!process.env.REPLICATE_API_TOKEN) {
throw new Error(
"The REPLICATE_API_TOKEN environment variable is not set. See README.md for instructions on how to set it."
);
}
const prediction = await replicate.predictions.create({
// Pinned to a specific version of Stable Diffusion
// See https://replicate.com/fofr/sticker-maker?input=http
version: "fbfe71bb555526d022edb3e87b5375ee4bd7500ac0467d0bca1942813f8d5b78",
// This is the text prompt that will be submitted by a form on the frontend
input: { prompt: req.body.prompt },
});
if (prediction?.error) {
res.statusCode = 500;
res.end(JSON.stringify({ detail: prediction.error }));
return;
}
res.statusCode = 201;
res.end(JSON.stringify(prediction));
}