Spaces:
Sleeping
Sleeping
Download frontend/src/api.ts from socks22/car-detection: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/socks22/car-detection/resolve/main/frontend/src/api.ts
- Command line
-
hf download hf://spaces/socks22/car-detection/frontend/src/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/socks22/car-detection/resolve/main/frontend/src/api.ts
1.09 kB
| 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(); | |
| } | |