From eed2c5482ee032fab956d6409837fbb23c8e34cd Mon Sep 17 00:00:00 2001 From: Vaibhav Srivastav Date: Mon, 16 Oct 2023 10:47:09 +0200 Subject: [PATCH] up --- js/src/lib/inferenceSnippets/serveJs.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js/src/lib/inferenceSnippets/serveJs.ts b/js/src/lib/inferenceSnippets/serveJs.ts index b94c3413c..f233efae4 100644 --- a/js/src/lib/inferenceSnippets/serveJs.ts +++ b/js/src/lib/inferenceSnippets/serveJs.ts @@ -56,6 +56,23 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => { // Use image });`; +export const snippetTextToAudio = (model: ModelData, accessToken: string): string => + `async function query(data) { + const response = await fetch( + "https://api-inference.huggingface.co/models/${model.id}", + { + headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" }, + method: "POST", + body: JSON.stringify(data), + } + ); + const result = await response.blob(); + return result; +} +query({"inputs": ${getModelInputSnippet(model)}}).then((response) => { + // Use Audio +});`; + export const snippetFile = (model: ModelData, accessToken: string): string => `async function query(filename) { const data = fs.readFileSync(filename);