mirror of
https://github.com/mito-systems/ranger-app.git
synced 2026-01-08 18:24:08 +00:00
47 lines
1.1 KiB
TypeScript
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'
|
|
}
|
|
}
|
|
}
|