Spaces:
Sleeping
Sleeping
File size: 856 Bytes
4e75170 0604cf4 4e75170 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // 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()
}
|