Download frontend/src/lib/api.ts from vipan-kumar/Audio_Deepfake_Detection: direct link, hf CLI and curl.
- Browser
- Download file 4.5 kB
-
https://huggingface.co/spaces/vipan-kumar/Audio_Deepfake_Detection/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/vipan-kumar/Audio_Deepfake_Detection/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/vipan-kumar/Audio_Deepfake_Detection/resolve/main/frontend/src/lib/api.ts
4.5 kB
| import axios from "axios"; | |
| import type { | |
| AdversarialPoint, | |
| BenchmarksResponse, | |
| DatasetInfo, | |
| DetectResponse, | |
| ExplainabilityExample, | |
| HealthResponse, | |
| MetricInfo, | |
| ModelEvaluation, | |
| ModelsListResponse, | |
| RadarResponse, | |
| SamplesResponse, | |
| VisualizeResponse, | |
| } from "@/types/inference"; | |
| const API_BASE_URL = | |
| (import.meta as ImportMeta & { env?: Record<string, string> }).env | |
| ?.VITE_API_BASE_URL || "http://localhost:8000"; | |
| const WS_BASE_URL = | |
| (import.meta as ImportMeta & { env?: Record<string, string> }).env | |
| ?.VITE_WS_BASE_URL || "ws://localhost:8000"; | |
| export const apiBaseUrl = API_BASE_URL; | |
| export const wsBaseUrl = WS_BASE_URL; | |
| export const api = axios.create({ | |
| baseURL: API_BASE_URL, | |
| timeout: 120_000, // first HF download can take a while | |
| }); | |
| // ---------------------------------------------------------------- meta -- // | |
| export async function getHealth(): Promise<HealthResponse> { | |
| const { data } = await api.get<HealthResponse>("/api/health"); | |
| return data; | |
| } | |
| export async function listModels(): Promise<ModelsListResponse> { | |
| const { data } = await api.get<ModelsListResponse>("/api/models"); | |
| return data; | |
| } | |
| export async function listSamples(): Promise<SamplesResponse> { | |
| const { data } = await api.get<SamplesResponse>("/api/samples"); | |
| return data; | |
| } | |
| export function sampleDownloadUrl(sampleId: string): string { | |
| return `${API_BASE_URL}/api/samples/${encodeURIComponent(sampleId)}/download`; | |
| } | |
| // ----------------------------------------------------------- benchmarks -- // | |
| export async function getBenchmarks(): Promise<BenchmarksResponse> { | |
| const { data } = await api.get<BenchmarksResponse>("/api/benchmarks"); | |
| return data; | |
| } | |
| export async function getRadar(): Promise<RadarResponse> { | |
| const { data } = await api.get<RadarResponse>("/api/benchmarks/radar"); | |
| return data; | |
| } | |
| export async function getHighlights(): Promise<{ highlights: string[] }> { | |
| const { data } = await api.get<{ highlights: string[] }>( | |
| "/api/benchmarks/highlights" | |
| ); | |
| return data; | |
| } | |
| export async function getBenchmarkDatasets(): Promise<{ datasets: DatasetInfo[] }> { | |
| const { data } = await api.get<{ datasets: DatasetInfo[] }>("/api/benchmarks/datasets"); | |
| return data; | |
| } | |
| export async function getBenchmarkMetrics(): Promise<{ metrics: MetricInfo[] }> { | |
| const { data } = await api.get<{ metrics: MetricInfo[] }>("/api/benchmarks/metrics"); | |
| return data; | |
| } | |
| export async function getModelEvaluations(): Promise<{ evaluations: ModelEvaluation[] }> { | |
| const { data } = await api.get<{ evaluations: ModelEvaluation[] }>("/api/benchmarks/evaluations"); | |
| return data; | |
| } | |
| export async function getAdversarialCurve(): Promise<{ epsilon_curve: AdversarialPoint[] }> { | |
| const { data } = await api.get<{ epsilon_curve: AdversarialPoint[] }>("/api/benchmarks/adversarial"); | |
| return data; | |
| } | |
| export async function getExplainabilityExamples(): Promise<{ examples: ExplainabilityExample[] }> { | |
| const { data } = await api.get<{ examples: ExplainabilityExample[] }>( | |
| "/api/benchmarks/explainability" | |
| ); | |
| return data; | |
| } | |
| // ------------------------------------------------------------ inference -- // | |
| export async function detectAudio( | |
| file: File, | |
| models?: string[], | |
| returnFeatures = true | |
| ): Promise<DetectResponse> { | |
| const fd = new FormData(); | |
| fd.append("audio_file", file); | |
| if (models && models.length) fd.append("models", JSON.stringify(models)); | |
| fd.append("return_features", String(returnFeatures)); | |
| const { data } = await api.post<DetectResponse>("/api/detect", fd, { | |
| headers: { "Content-Type": "multipart/form-data" }, | |
| }); | |
| return data; | |
| } | |
| export async function detectSample( | |
| sampleId: string, | |
| models?: string[], | |
| returnFeatures = true | |
| ): Promise<DetectResponse> { | |
| const fd = new FormData(); | |
| if (models && models.length) fd.append("models", JSON.stringify(models)); | |
| fd.append("return_features", String(returnFeatures)); | |
| const { data } = await api.post<DetectResponse>( | |
| `/api/detect/sample/${encodeURIComponent(sampleId)}`, | |
| fd | |
| ); | |
| return data; | |
| } | |
| export async function visualizeAudio(file: File): Promise<VisualizeResponse> { | |
| const fd = new FormData(); | |
| fd.append("audio_file", file); | |
| const { data } = await api.post<VisualizeResponse>("/api/visualize", fd, { | |
| headers: { "Content-Type": "multipart/form-data" }, | |
| }); | |
| return data; | |
| } | |
| export function inferenceWebSocketUrl(sessionId: string): string { | |
| return `${WS_BASE_URL}/ws/inference/${encodeURIComponent(sessionId)}`; | |
| } | |