Skip to content

Commit

Permalink
vision 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanCantCode committed Aug 3, 2024
1 parent bd479a9 commit 352c115
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions utils/visionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import vision from '@google-cloud/vision';

let client: vision.ImageAnnotatorClient;
interface VisionClient {
labelDetection: (request: { image: { content: Buffer } }) => Promise<{ labelAnnotations: { description: string, score: number }[] }[]>;
}

let client: VisionClient;

try {
const clientEmail = process.env.EMAIL;
Expand All @@ -15,11 +19,11 @@ try {
private_key: privateKey,
};

client = new vision.ImageAnnotatorClient({ credentials });
client = new vision.ImageAnnotatorClient({ credentials }) as VisionClient;
} catch (error) {
console.error('Error parsing Google Cloud credentials:', error);
// Initialize with default credentials as a fallback
client = new vision.ImageAnnotatorClient();
client = new vision.ImageAnnotatorClient() as VisionClient;
}

export const scanProduct = async (imageData: string): Promise<{ name: string; quantity: number; allLabels: string[] }> => {
Expand Down

0 comments on commit 352c115

Please sign in to comment.