|
const TOKEN = "";
|
|
|
|
async function query(chooseModel, token = TOKEN) {
|
|
try {
|
|
const response = await fetch(
|
|
`https://api-inference.huggingface.co/models/${chooseModel}`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"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;
|
|
}
|
|
}
|
|
|