socks22's picture
two models
4bce717
const API_URL = (import.meta.env.VITE_API_URL as string) || 'http://localhost:8000';
export type ModelType = 'cars' | 'spots';
export interface Detection {
bbox: [number, number, number, number];
score: number;
class_id: number;
class_name: string;
}
export interface Occupancy {
empty_count: number;
occupied_count: number;
total_spots: number;
occupancy_rate: number;
}
export interface DetectResponse {
model: string;
car_count: number;
detections: Detection[];
annotated_image: string;
heatmap_image: string;
occupancy?: Occupancy;
}
export async function detectCars(
file: File,
threshold: number = 0.5,
model: ModelType = 'cars'
): Promise<DetectResponse> {
const form = new FormData();
form.append('file', file);
const res = await fetch(
`${API_URL}/detect?threshold=${threshold}&model=${model}`,
{
method: 'POST',
body: form,
}
);
if (!res.ok) {
const err = await res.json().catch(() => ({ error: 'Request failed' }));
throw new Error(err.error ?? `HTTP ${res.status}`);
}
return res.json();
}