xxxxxxxxxx
68
const replicateProxy = "https://replicate-api-proxy.glitch.me";
let feedback;
let img;
function setup() {
createCanvas(768, 1280);
let input_image_field = createInput(
"A beautiful painting of a old lady, shining its light across the room by Rembrandt, Trending on artstation."
//old brazilian man, by the sea, portrait photography, beautiful, sunlight, smooth light, real photography fujifilm superia, full HD, taken on a Canon EOS R5 F1.2 ISO100 35MM --ar 4:3 --s 750
//a cell tower disguised as tree, portrait photography, beautiful, sunlight, smooth light, real photography fujifilm superia, full HD, taken on a Canon EOS R5 F1.2 ISO100 35MM --ar 4:3 --s 750
);
input_image_field.size(450);
input_image_field.id("input_image_prompt");
input_image_field.position(10,10);
//add a button to ask for picture
let button = createButton("Ask");
button.position(460,10);
button.mousePressed(() => {
askForPicture(input_image_field.value());
});
feedback = createP("");
feedback.position(0,20)
}
function draw(){
if (img) image(img, 0, 0, width, height);
}
async function askForPicture(p_prompt) {
const imageDiv = select("#resulting_image");
feedback.html("Waiting for reply from Replicate's Stable Diffusion API...");
let data = {
version: "da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
input: {
prompt: p_prompt,
negative_prompt: "",
num_inference_steps: 100,
guidance_scale: 7.5,
// seed: 32,
width: 768,
height: 1280,
scheduler: "DDIM",
// scheduler: "K_EULER_ANCESTRAL",
},
};
console.log("Asking for Picture Info From Replicate via Proxy", data);
let options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
};
const url = replicateProxy + "/create_n_get/";
const picture_info = await fetch(url, options);
//turn the stuff coming back into json
const proxy_said = await picture_info.json();
if (proxy_said.output.length == 0) {
feedback.html("Something went wrong, try it again");
} else {
feedback.html("");
loadImage(proxy_said.output[0], (incomingImage) => {
img = incomingImage
});
}
}