logging and add rodent to list
This commit is contained in:
parent
cc8bc7f057
commit
f4dde9b83d
@ -1,3 +1,3 @@
|
|||||||
// src/services/constants.ts
|
// 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']
|
||||||
|
@ -4,8 +4,9 @@ import { ANIMAL_LABELS } from './constants'
|
|||||||
|
|
||||||
export interface VisionAnalysisResult {
|
export interface VisionAnalysisResult {
|
||||||
description: string
|
description: string
|
||||||
mainObject: string // Added to store the primary detected object
|
mainObject: string
|
||||||
isAnimal: boolean
|
isAnimal: boolean
|
||||||
|
matchedLabel: string // Add this to store which label was matched
|
||||||
rawResponse: any
|
rawResponse: any
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,14 +53,18 @@ export async function analyzeImageWithVision(imageBuffer: Buffer): Promise<Visio
|
|||||||
const labels = data.responses[0]?.labelAnnotations || []
|
const labels = data.responses[0]?.labelAnnotations || []
|
||||||
const objects = data.responses[0]?.localizedObjectAnnotations || []
|
const objects = data.responses[0]?.localizedObjectAnnotations || []
|
||||||
|
|
||||||
const isAnimal = labels.some(label =>
|
// Find the matching animal label
|
||||||
|
const matchedLabel = labels.find(label =>
|
||||||
ANIMAL_LABELS.includes(label.description.toLowerCase())
|
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
|
// Get the first animal label as main object
|
||||||
const mainObject = labels.find(label =>
|
const mainObject = matchedLabel || 'Unknown'
|
||||||
ANIMAL_LABELS.includes(label.description.toLowerCase())
|
|
||||||
)?.description || 'Unknown'
|
|
||||||
|
|
||||||
const { description } = constructDescription(labels, objects)
|
const { description } = constructDescription(labels, objects)
|
||||||
|
|
||||||
@ -67,6 +72,7 @@ export async function analyzeImageWithVision(imageBuffer: Buffer): Promise<Visio
|
|||||||
description,
|
description,
|
||||||
mainObject,
|
mainObject,
|
||||||
isAnimal,
|
isAnimal,
|
||||||
|
matchedLabel,
|
||||||
rawResponse: data.responses[0]
|
rawResponse: data.responses[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +89,6 @@ function constructDescription(labels: any[], objects: any[]): { description: str
|
|||||||
.filter((value, index, self) => self.indexOf(value) === index)
|
.filter((value, index, self) => self.indexOf(value) === index)
|
||||||
.slice(0, 3)
|
.slice(0, 3)
|
||||||
|
|
||||||
// Only include "The scene includes..." part as description
|
|
||||||
let description = "The scene includes "
|
let description = "The scene includes "
|
||||||
description += topLabels.join(", ") + "."
|
description += topLabels.join(", ") + "."
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user