Skip to content

Commit

Permalink
Update visionUtils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanCantCode authored Aug 2, 2024
1 parent 62a894b commit dbefbf9
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions utils/visionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ export const scanProduct = async (imageData: string): Promise<{ name: string; qu

const labels = result.labelAnnotations || [];

// Filter out generic labels
const specificLabels = labels.filter(label =>
label.description && !['Food', 'Produce', 'Natural foods', 'Fruit', 'Vegetable'].includes(label.description)
);

if (specificLabels.length > 0) {
// Use the most confident specific label
const productName = specificLabels[0]?.description || 'Unknown Product';

// Log all labels for debugging
console.log('All labels:', labels.map(l => `${l.description || 'Unknown'} (${l.score || 'N/A'})`).join(', '));

return { name: productName, quantity: 1, allLabels: labels.map(label => label.description || '').filter(Boolean) };
} else if (labels.length > 0) {
// If no specific labels, use the most confident general label
const productName = labels[0]?.description || 'Unknown Product';
return { name: productName, quantity: 1, allLabels: labels.map(label => label.description || '').filter(Boolean) };
} else {
Expand Down

0 comments on commit dbefbf9

Please sign in to comment.