eladrich
/
pixel2style2pixel
a StyleGAN Encoder for Image-to-Image Translation
Run eladrich/pixel2style2pixel with an API
- Preferstring
Leave the request open and wait for the model to finish generating output. Set to
wait=n
where n is a number of seconds between 1 and 60.See https://replicate.com/docs/topics/predictions/create-a-prediction#sync-mode for more information.
- inputobjectRequired
The model's input as a JSON object. The input schema depends on what model you are running. To see the available inputs, click the "API" tab on the model you are running or get the model version and look at its
openapi_schema
property. For example, stability-ai/sdxl takesprompt
as an input.Files should be passed as HTTP URLs or data URLs.
Use an HTTP URL when:
- you have a large file > 256kb
- you want to be able to use the file multiple times
- you want your prediction metadata to be associable with your input files
Use a data URL when:
- you have a small file <= 256kb
- you don't want to upload and host the file somewhere
- you don't need to use the file again (Replicate will not store it)
- versionstringRequired
The ID of the model version that you want to run.
- webhookstring
An HTTPS URL for receiving a webhook when the prediction has new output. The webhook will be a POST request where the request body is the same as the response body of the get prediction operation. If there are network problems, we will retry the webhook a few times, so make sure it can be safely called more than once. Replicate will not follow redirects when sending webhook requests to your service, so be sure to specify a URL that will resolve without redirecting.
- webhook_events_filterarray
By default, we will send requests to your webhook URL whenever there are new outputs or the prediction has finished. You can change which events trigger webhook requests by specifying
webhook_events_filter
in the prediction request:start
: immediately on prediction startoutput
: each time a prediction generates an output (note that predictions can generate multiple outputs)logs
: each time log output is generated by a predictioncompleted
: when the prediction reaches a terminal state (succeeded/canceled/failed)
For example, if you only wanted requests to be sent at the start and end of the prediction, you would provide:
{ "version": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", "input": { "text": "Alice" }, "webhook": "https://example.com/my-webhook", "webhook_events_filter": ["start", "completed"] }
Requests for event types
output
andlogs
will be sent at most once every 500ms. If you requeststart
andcompleted
webhooks, then they'll always be sent regardless of throttling.
Create a prediction and get the output
import Replicate from "replicate";
const replicate = new Replicate();
const input = {
image: "https://replicate.delivery/mgxm/7935db96-ae91-440f-8c75-b94bd6315d79/input_img.jpg",
model: "toonify"
};
const output = await replicate.run("eladrich/pixel2style2pixel:919ed2f7b6c5c24f3a53207842b61b6eba515136bd7bb9ffa75e01e970609cc4", { input });
import { writeFile } from "node:fs/promises";
await writeFile("output", output);
//=> output written to disk
- prediction_idstringRequiredThe ID of the prediction to get.
Get the latest version of a prediction by id
import Replicate from "replicate";
const replicate = new Replicate();
console.log("Getting prediction...")
const prediction = await replicate.predictions.get(predictionId);
//=> {"id": "xyz...", "status": "successful", ... }
- prediction_idstringRequiredThe ID of the prediction to cancel.
Cancel an in progress prediction
import Replicate from "replicate";
const replicate = new Replicate();
console.log("Canceling prediction...")
const prediction = await replicate.predictions.cancel(predictionId);
//=> {"id": "xyz...", "status": "canceled", ... }
List the first page of your predictions
import Replicate from "replicate";
const replicate = new Replicate();
const page = await replicate.predictions.list();
console.log(page.results)
//=> [{ "id": "xyz...", "status": "successful", ... }, { ... }]