From f99920b0abbb0a25d5529282c760d09840cf04a8 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 4 Jul 2024 23:35:39 +0530 Subject: [PATCH] updates --- utils/gpt.js | 38 ++++---- views/index.ejs | 231 ------------------------------------------------ 2 files changed, 21 insertions(+), 248 deletions(-) delete mode 100644 views/index.ejs diff --git a/utils/gpt.js b/utils/gpt.js index 278c96f..2534bf1 100644 --- a/utils/gpt.js +++ b/utils/gpt.js @@ -1,33 +1,37 @@ const { GoogleGenerativeAI } = require("@google/generative-ai"); const fs = require("fs"); -require('dotenv').config(); +require("dotenv").config(); const genAI = new GoogleGenerativeAI(process.env.API_KEY); // Converts local file information to a GoogleGenerativeAI.Part object. function fileToGenerativePart(path, mimeType) { - return { - inlineData: { - data: Buffer.from(fs.readFileSync(path)).toString("base64"), - mimeType - }, - }; - } + return { + inlineData: { + data: Buffer.from(fs.readFileSync(path)).toString("base64"), + mimeType, + }, + }; +} -async function run(path,mimeType) { +async function run(path, mimeType) { + try { // For text-and-image input (multimodal), use the gemini-pro-vision model // console.log(process.env.API_KEY) const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" }); - const prompt = "extract id number, name, last name, date of birth, date of issue and date of expiry from the given image in english and convert date into dd/mm/yyyy format and only have dd/mm/yyyy format,if any data missing mark it as NA"; - const imageParts = [ - fileToGenerativePart(path,mimeType) - ]; - - const result = await model.generateContent([prompt,...imageParts]); + const prompt = + "extract id number, name, last name, date of birth, date of issue and date of expiry from the given image in english and convert date into dd/mm/yyyy format and only have dd/mm/yyyy format,if any data missing mark it as NA"; + const imageParts = [fileToGenerativePart(path, mimeType)]; + + const result = await model.generateContent([prompt, ...imageParts]); const response = await result.response; const text = response.text(); console.log(text); return text; + } catch (err) { + console.error(err); + return "NA"; } - -module.exports = {run} +} + +module.exports = { run }; diff --git a/views/index.ejs b/views/index.ejs deleted file mode 100644 index 6199b25..0000000 --- a/views/index.ejs +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - ID Detector - - - - -

ID Scanner

- Github -
-

Use only png and jpeg.

-
- -
- -
-
- -

Result:

- -
- -
-

Filter:

-
- - - - - - - - - -
-
-
-

Uploaded Images:

-
- - - - - - - - - \ No newline at end of file