Spaces:
Paused
Paused
Download frontend/lib/api.ts from akagtag/deepdetection: direct link, hf CLI and curl.
- Browser
- Download file 856 Bytes
-
https://huggingface.co/spaces/akagtag/deepdetection/resolve/main/frontend/lib/api.ts
- Command line
-
hf download hf://spaces/akagtag/deepdetection/frontend/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/akagtag/deepdetection/resolve/main/frontend/lib/api.ts
856 Bytes
| // frontend/lib/api.ts | |
| import type { DetectionResponse } from '@/types/detection' | |
| const BASE_URL = '/api' | |
| async function _post(endpoint: string, file: File): Promise<DetectionResponse> { | |
| const form = new FormData() | |
| form.append('file', file) | |
| const res = await fetch(`${BASE_URL}${endpoint}`, { | |
| method: 'POST', | |
| body: form, | |
| }) | |
| if (!res.ok) { | |
| const err = await res.text() | |
| throw new Error(`Detection failed (${res.status}): ${err}`) | |
| } | |
| return res.json() | |
| } | |
| export const detectImage = (file: File) => _post('/detect/image', file) | |
| export const detectVideo = (file: File) => _post('/detect/video', file) | |
| export async function healthCheck(): Promise<{ status: string; version?: string }> { | |
| const res = await fetch(`${BASE_URL}/health`) | |
| if (!res.ok) throw new Error(`Health check failed: ${res.status}`) | |
| return res.json() | |
| } | |