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 c6ec39b commit 500bac8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions utils/visionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export const scanProduct = async (imageData: string): Promise<{ name: string; qu

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

// Log all labels for debugging
console.log('All labels:', labels.map(l => `${l.description} (${l.score})`).join(', '));
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;
const productName = labels[0]?.description || 'Unknown Product';
return { name: productName, quantity: 1, allLabels: labels.map(label => label.description || '').filter(Boolean) };
} else {
throw new Error('No labels detected in the image');
Expand Down

0 comments on commit 500bac8

Please sign in to comment.