|
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; |
|
} |
|
} |
|
|