xxxxxxxxxx
55
const api_key = "SG_****************";
let picture; //画像の変数imgを定義
function preload() {
}
function setup() {
createCanvas(500, 500);
const url = "https://api.segmind.com/v1/ssd-1b";
const data = {
prompt: "Samoyed dog playing club DJ.",
negative_prompt: "painting",
samples: 1,
scheduler: "UniPC",
num_inference_steps: 20,
guidance_scale: 9,
img_width: 1024,
img_height: 1024,
base64: false
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": api_key,
},
body: JSON.stringify(data),
})
.then((response) => {
return response.blob();
})
.then((data) => {
var reader = new FileReader();
reader.onload = function (evt) {
picture = loadImage(reader.result);
};
reader.readAsDataURL(data);
})
.catch((error) => console.log("error", error));
}
const pictureWidth = 500;
const pictureHeight = 500;
function draw() {
if (picture === undefined) {
return;
}
image(picture, 0, 0, 500, 500);
}