Prav51's picture
Removed Token words
8d6ff28 verified
raw
history blame contribute delete
785 Bytes
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
}
}