ranger-app/src/services/googleVisionService.ts
2025-01-09 12:32:34 -05:00

47 lines
1.1 KiB
TypeScript

// src/services/googleVisionService.ts
export interface VisionAnalysisResult {
description?: string
error?: string
isAnimal?: boolean
rawResponse?: any
}
export interface VisionConfig {
modelId: string
name: string
description: string
cost: number
}
export const VISION_CONFIG: VisionConfig = {
modelId: "google-vision-v1",
name: "Worldwide Animal Oracle",
description: "Upload photos of your wildlife encounters from the real world. Verified animal images will be added to the Animal Registry.",
cost: 3
}
export async function analyzeImage(imageFile: File): Promise<VisionAnalysisResult> {
try {
const formData = new FormData()
formData.append('image', imageFile)
const response = await fetch('/api/analyze', {
method: 'POST',
body: formData
})
if (!response.ok) {
const error = await response.json()
throw new Error(error.error || 'Failed to analyze image')
}
return await response.json()
} catch (error) {
console.error('Vision analysis error:', error)
return {
error: error instanceof Error ? error.message : 'Failed to analyze image'
}
}
}