Closed MenlyCSE closed 3 months ago
Implemented a better UI for the Gemini API website, and everything other then the input and summarize button are placeholders for now. Using the API and uses User input to generate AI responses
const {VertexAI} = require('@google-cloud/vertexai');
/**
* TODO(developer): Update these variables before running the sample.
*/
async function analyze_pdf(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});
const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-1.5-flash-001',
});
const filePart = {
file_data: {
file_uri: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
mime_type: 'application/pdf',
},
};
const textPart = {
text: `
You are a very professional document summarization specialist.
Please summarize the given document.`,
};
const request = {
contents: [{role: 'user', parts: [filePart, textPart]}],
};
const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
}
It's hard to find a pure JavaScript approach for PDF uploads, but I found this Node.js approach that seems to work pretty well. This one logs the response to the console but it easy to update the website with it. A similar approach can be used to upload the regular prompts too.
Use Google's API to generate or summarize text in our HTML, CSS, and JavaScript webpage.
Do whatever you'd like as long as you are using Google's API