Spaces:
Sleeping
Sleeping
Download ui/src/api.ts from metzgerdev/vocal-semantic-search: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/metzgerdev/vocal-semantic-search/resolve/main/ui/src/api.ts
- Command line
-
hf download hf://spaces/metzgerdev/vocal-semantic-search/ui/src/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/metzgerdev/vocal-semantic-search/resolve/main/ui/src/api.ts
1.66 kB
| import type { | |
| CatalogInfo, | |
| Evaluation, | |
| Filters, | |
| Heatmap, | |
| ProjectionPoint, | |
| SearchResponse, | |
| Robustness, | |
| SimilarResponse, | |
| } from "./types"; | |
| async function get<T>(path: string): Promise<T> { | |
| const res = await fetch(path); | |
| if (!res.ok) throw new Error(`${path} -> ${res.status} ${res.statusText}`); | |
| return res.json() as Promise<T>; | |
| } | |
| export const getCatalog = () => get<CatalogInfo>("/api/catalog"); | |
| export const getEvaluation = () => get<Evaluation>("/api/evaluation"); | |
| export const getRobustness = () => get<Robustness>("/api/robustness"); | |
| export const getProjection = () => | |
| get<{ points: ProjectionPoint[] }>("/api/projection").then((d) => d.points); | |
| export const getSimilar = (id: string, k = 6) => | |
| get<SimilarResponse>(`/api/voices/${id}/similar?k=${k}`); | |
| export async function search( | |
| query: string, | |
| topN = 12, | |
| filters: Filters = {}, | |
| ): Promise<SearchResponse> { | |
| const res = await fetch("/api/search", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ query, topN, filters }), | |
| }); | |
| if (!res.ok) { | |
| const detail = await res.json().catch(() => null); | |
| throw new Error(detail?.detail ?? `search failed (${res.status})`); | |
| } | |
| return res.json(); | |
| } | |
| export async function heatmap(query: string, topN = 10): Promise<Heatmap> { | |
| const res = await fetch("/api/heatmap", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ query, topN }), | |
| }); | |
| if (!res.ok) { | |
| const detail = await res.json().catch(() => null); | |
| throw new Error(detail?.detail ?? `heatmap failed (${res.status})`); | |
| } | |
| return res.json(); | |
| } | |