File size: 785 Bytes
8d6ff28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
const TKN = "";
async function query(chooseModel, yourKy = TKN) {
try {
const response = await fetch(
`https://api-inference.huggingface.co/models/${chooseModel}`,
{
headers: {
Authorization: `Bearer ${yourKy}`,
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({ inputs: text.value }),
}
);
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
const result = await response.blob();
return result;
} catch (error) {
notificationInstance.show(
"error",
"Error fetching the image. Please try again later."
);
throw error; // Re-throw the error to handle it in the click event listener
}
}
|