xxxxxxxxxx
75
let img; //画像の変数imgを定義
function setup() {
createCanvas(512, 512);
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = "a7e02f595d6f4c37b51772da52e18f0e";
// Specify the correct user_id/app_id pairings
// Since you're making inferences outside your app's scope
const USER_ID = "segmind";
const APP_ID = "segmind-stable-diffusion";
// Change these to whatever model and text you want to use
const MODEL_ID = "ssd-1b";
const MODEL_VERSION_ID = "5cc1a784916a402eac8b8f51391ed15b";
const RAW_TEXT = "Parrot wearing sunglasses.";
// To use a hosted text file, assign the URL variable
// const TEXT_FILE_URL = 'https://samples.clarifai.com/negative_sentence_12.txt'
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
inputs: [
{
data: {
text: {
raw: RAW_TEXT,
// "url": TEXT_FILE_URL
},
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/models/ssd-1b/versions/${MODEL_VERSION_ID}/outputs`,
requestOptions
)
.then((response) => response.json())
.then((result) => {
const imageBase64 = result.outputs[0].data.image.base64;
// Create an anchor element for downloading the image
img = loadImage(`data:image/jpeg;base64,${imageBase64}`);//画像を読み込む
console.log("done")
})
.catch((error) => console.log("error", error));
}
function draw() {
background(220);
if(img === undefined){
return;
}
try {
image(img,0,0, img.width / 2, img.height / 2);//画像を表示
}catch (error) {
console.error(error);
console.log(typeof img);
console.log(img)
}
}