mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
Added comments to my code to make it more understandable
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { GoogleGenAI } = require("@google/genai");
|
const { GoogleGenAI } = require("@google/genai"); // Import Google Gemini AI SDK
|
||||||
|
|
||||||
const outputDir = path.join(__dirname, "../../../storage/documents");
|
const outputDir = path.join(__dirname, "../../../storage/documents"); // path for output directory
|
||||||
|
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true }); // Create output directory if it doesn't exist
|
||||||
}
|
}
|
||||||
|
|
||||||
const ai = new GoogleGenAI({
|
const ai = new GoogleGenAI({
|
||||||
apiKey: process.env.GOOGLE_API_KEY
|
apiKey: process.env.GOOGLE_API_KEY // Ensure Google API key is set in environment variables: export GOOGLE_API_KEY="your_api_key_here"
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -22,10 +22,10 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
console.log("Gemini LLM module invoked with parameters:", parameter);
|
console.log("Gemini LLM module invoked with parameters:", parameter);
|
||||||
|
|
||||||
await this.createDocumentFromTranscript(
|
await this.createDocumentFromTranscript( //Call the function to create document with transcript, document type and language
|
||||||
parameter.inputTranscriptPath,
|
parameter.inputTranscriptPath, // Path to input transcript file
|
||||||
parameter.documentTypePath,
|
parameter.documentTypePath, // Path to document type file which is chosen in the front end by the user
|
||||||
parameter.language
|
parameter.language // Language for the document which is chosen in the front end by the user
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -33,7 +33,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") {
|
createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") { // default language is English
|
||||||
try {
|
try {
|
||||||
const transcript = await fs.promises.readFile(transcriptPath, "utf-8");
|
const transcript = await fs.promises.readFile(transcriptPath, "utf-8");
|
||||||
const documentType = await fs.promises.readFile(documentTypePath, "utf-8");
|
const documentType = await fs.promises.readFile(documentTypePath, "utf-8");
|
||||||
@@ -41,14 +41,14 @@ module.exports = {
|
|||||||
const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`;
|
const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`;
|
||||||
|
|
||||||
const response = await ai.models.generateContent({
|
const response = await ai.models.generateContent({
|
||||||
model: "gemini-2.5-flash",
|
model: "gemini-2.5-flash", // Specify the Gemini model to use
|
||||||
contents: promptText
|
contents: promptText // Input prompt for content generation
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = response.text || "";
|
const output = response.text || ""; // Get generated text from response or default to empty string (if null)
|
||||||
|
|
||||||
const outPath = path.join(outputDir, "test.md");
|
const outPath = path.join(outputDir, "test.md"); // Output file path & name TO BE DONE to make dynamic out of input transcript name
|
||||||
fs.writeFileSync(outPath, output, "utf8");
|
fs.writeFileSync(outPath, output, "utf8"); // Write output to file
|
||||||
|
|
||||||
console.log("Generated document written to:", outPath);
|
console.log("Generated document written to:", outPath);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user