diff --git a/src/services/constants.ts b/src/services/constants.ts index f086601..31ca836 100644 --- a/src/services/constants.ts +++ b/src/services/constants.ts @@ -1,3 +1,3 @@ // src/services/constants.ts -export const ANIMAL_LABELS = ['animal', 'wildlife', 'mammal', 'bird', 'reptile', 'amphibian', 'nature', 'cat', 'mouse', 'insect', 'vertebrate', 'dog'] +export const ANIMAL_LABELS = ['animal', 'wildlife', 'mammal', 'bird', 'reptile', 'amphibian', 'nature', 'cat', 'mouse', 'insect', 'vertebrate', 'dog', 'rodent'] diff --git a/src/services/googleVisionCore.ts b/src/services/googleVisionCore.ts index 6017fff..599c7af 100644 --- a/src/services/googleVisionCore.ts +++ b/src/services/googleVisionCore.ts @@ -4,8 +4,9 @@ import { ANIMAL_LABELS } from './constants' export interface VisionAnalysisResult { description: string - mainObject: string // Added to store the primary detected object + mainObject: string isAnimal: boolean + matchedLabel: string // Add this to store which label was matched rawResponse: any } @@ -52,14 +53,18 @@ export async function analyzeImageWithVision(imageBuffer: Buffer): Promise + // Find the matching animal label + const matchedLabel = labels.find(label => ANIMAL_LABELS.includes(label.description.toLowerCase()) - ) + )?.description || '' + + console.log('Vision API labels:', labels.map(l => l.description)) + console.log('Matched animal label:', matchedLabel) + + const isAnimal = !!matchedLabel // Get the first animal label as main object - const mainObject = labels.find(label => - ANIMAL_LABELS.includes(label.description.toLowerCase()) - )?.description || 'Unknown' + const mainObject = matchedLabel || 'Unknown' const { description } = constructDescription(labels, objects) @@ -67,6 +72,7 @@ export async function analyzeImageWithVision(imageBuffer: Buffer): Promise self.indexOf(value) === index) .slice(0, 3) - // Only include "The scene includes..." part as description let description = "The scene includes " description += topLabels.join(", ") + "."