Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
furiousluck committed Jul 4, 2024
1 parent 8b4923d commit f99920b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 248 deletions.
38 changes: 21 additions & 17 deletions utils/gpt.js
Original file line number Diff line number Diff line change
@@ -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 };
231 changes: 0 additions & 231 deletions views/index.ejs

This file was deleted.

0 comments on commit f99920b

Please sign in to comment.