Download frontend/static/api.js from build-small-hackathon/sofia-educational-companion: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/build-small-hackathon/sofia-educational-companion/resolve/main/frontend/static/api.js
- Command line
-
hf download hf://spaces/build-small-hackathon/sofia-educational-companion/frontend/static/api.js
-
curl -L -o api.js https://huggingface.co/spaces/build-small-hackathon/sofia-educational-companion/resolve/main/frontend/static/api.js
1.11 kB
| // api.js — conexión compartida al backend Gradio (chat / transcribe / speak). | |
| import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js"; | |
| let clientPromise = null; | |
| export function getClient() { | |
| if (!clientPromise) { | |
| clientPromise = Client.connect(window.location.origin); | |
| } | |
| return clientPromise; | |
| } | |
| export async function transcribe(blob, ext, durationMs) { | |
| const client = await getClient(); | |
| const audioFile = new File([blob], `audio.${ext}`, { type: blob.type }); | |
| const r = await client.predict("/transcribe", { audio: audioFile, duration_ms: durationMs }); | |
| return r.data?.[0] ?? {}; | |
| } | |
| export async function chat(message, childAge = 3) { | |
| const client = await getClient(); | |
| const r = await client.predict("/chat", { message, child_age: childAge }); | |
| return r.data?.[0] ?? {}; | |
| } | |
| export async function speak(text) { | |
| const client = await getClient(); | |
| const r = await client.predict("/speak", { text }); | |
| // FileData puede venir con .url o con .path (Gradio lo resuelve según versión) | |
| const fd = r.data?.[0]; | |
| return fd?.url ?? fd?.path ?? ""; | |
| } | |