-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b4923d
commit f99920b
Showing
2 changed files
with
21 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file was deleted.
Oops, something went wrong.