enzostvs's picture
enzostvs HF Staff
sentiment analysis
19e4f9a
raw
history blame
930 Bytes
import { error, json, type RequestEvent } from '@sveltejs/kit';
import { env } from '$env/dynamic/private'
/** @type {import('./$types').RequestHandler} */
export async function POST({ request }: RequestEvent) {
const body = await request?.json().catch(() => {});
if (!body?.inputs || body.inputs === null) {
throw error(400, 'missing inputs value')
}
const response = await fetch(env.SECRET_INFERENCE_API_URL + "/models/lxyuan/distilbert-base-multilingual-cased-sentiments-student", {
method: "POST",
headers: {
Authorization: `Bearer ${env.SECRET_HF_TOKEN}`,
'Content-Type': 'application/json',
['x-use-cache']: "0"
},
body: JSON.stringify(body),
})
.then((res) => res.json())
.then((res) => res)
.catch((error) => {
return {
error: error.message,
}
})
if ("error" in response) {
error(400, response.error as string)
}
return json(response)
}