Spaces:
Build error
Build error
File size: 2,130 Bytes
583e46a | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | const API_BASE_URL = import.meta.env.VITE_API_URL || '';
export async function predictFromFile(file, topK = 3) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch(`${API_BASE_URL}/predict/file?top_k=${topK}`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.detail || 'Prediction failed');
}
return response.json();
}
export async function predictFromURL(url, topK = 3) {
const response = await fetch(`${API_BASE_URL}/predict/url`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url, top_k: topK }),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.detail || 'Prediction failed');
}
return response.json();
}
export async function predictFromBase64(base64Image, topK = 3) {
const response = await fetch(`${API_BASE_URL}/predict/base64`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: base64Image, top_k: topK }),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.detail || 'Prediction failed');
}
return response.json();
}
export async function getBreeds(animalType, search) {
const params = new URLSearchParams();
if (animalType) params.append('animal_type', animalType);
if (search) params.append('search', search);
const response = await fetch(`${API_BASE_URL}/breeds?${params}`);
if (!response.ok) throw new Error('Failed to fetch breeds');
return response.json();
}
export async function getBreedDetail(breedName) {
const response = await fetch(`${API_BASE_URL}/breeds/${encodeURIComponent(breedName)}`);
if (!response.ok) throw new Error('Breed not found');
return response.json();
}
export async function getHealth() {
const response = await fetch(`${API_BASE_URL}/health`);
return response.json();
}
export async function getVersion() {
const response = await fetch(`${API_BASE_URL}/version`);
return response.json();
}
|