Skip to content

Commit

Permalink
default to public model and make deployments opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Sep 25, 2023
1 parent 62950ff commit d034840
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ DATABASE_URL=
# so the Replicate API can send it webhooks
#
# e.g. https://8db01fea81ad.ngrok.io
NGROK_HOST=
NGROK_HOST=


# Optional: Set a value for this to run the private Replicate deployment of the model
# instead of the public ControlNet Scribble model.
USE_REPLICATE_DEPLOYMENT=
27 changes: 19 additions & 8 deletions pages/api/predictions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,32 @@ export default async function handler(req) {

const input = await getObjectFromRequestBodyStream(req.body);

// https://replicate.com/rossjillian/controlnet

const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});

const prediction = await replicate.deployments.predictions.create(
"replicate",
"scribble-diffusion-jagilley-controlnet",
{
let prediction;

if (process.env.USE_REPLICATE_DEPLOYMENT) {
prediction = await replicate.deployments.predictions.create(
"replicate",
"scribble-diffusion-jagilley-controlnet",
{
input,
webhook: `${WEBHOOK_HOST}/api/replicate-webhook`,
webhook_events_filter: ["start", "completed"],
}
);
} else {
// https://replicate.com/jagilley/controlnet-scribble/versions
prediction = await replicate.predictions.create({
version:
"435061a1b5a4c1e26740464bf786efdfa9cb3a3ac488595a2de23e143fdb0117",
input,
webhook: `${WEBHOOK_HOST}/api/replicate-webhook`,
webhook_events_filter: ["start", "completed"],
}
);
});
}

if (prediction?.error) {
return NextResponse.json({ detail: prediction.error }, { status: 500 });
Expand Down

0 comments on commit d034840

Please sign in to comment.