akagtag's picture
feat: update frontend to proxy requests to Hugging Face Space API and configure environment variables
0604cf4
// 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()
}