-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 923 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/stability-ai/sdxl
version: "8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f",
// 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));
}