mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
faee605f12
Added mocha based unit tests for each module Did a bit of cleanup in the modules to remove debug console.log calls Removed the Progress bar in the extractor and the library requirement Promisified the gemini module to make sure it returns the path as a promise instead of just on the cli Fixed gitignore so that it now only ignores the content int the storage directories, and not the whole directories Added neetingReport.json for the LLMs to use
256 lines
8.6 KiB
JavaScript
256 lines
8.6 KiB
JavaScript
// Loading required packages
|
|
require("./requires.js")
|
|
console.log(start);
|
|
|
|
|
|
// Initialising map to be used to store the functionality later on for reloadability
|
|
mapFunctions = new Map()
|
|
|
|
|
|
// Loading the Function Map
|
|
var path = `${mainDir}/services/modules`
|
|
var folders = fs.readdirSync(path).filter(function (file) {
|
|
return fs.statSync(path+'/'+file).isDirectory();
|
|
});
|
|
folders.forEach(element => {
|
|
var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
|
|
for (const file of commandFiles) {
|
|
delete require.cache[require.resolve(`${path}/${element}/${file}`)];
|
|
const command = require(`${path}/${element}/${file}`);
|
|
mapFunctions.set(command.name, command);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// The startup information for the project, here you can add stuff that might be nice to see when the app starts
|
|
mapFunctions.get("Startup_function").function()
|
|
console.log("------------------------------------ Status ------------------------------------");
|
|
console.log(__dirname);
|
|
console.log(platform);
|
|
console.log(`The Startup took ${new Date() - start}ms`)
|
|
console.log(`${mapFunctions.size} Function modules loaded`);
|
|
console.log("--------------------------------------------------------------------------------");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------- CLI COMMANDS --------------------------------------------------------- //
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
|
|
rl.on("line", data =>{
|
|
const args = data.trim().split(" ");
|
|
const command = args.shift().toLowerCase();
|
|
mapFunctions.get("cliCommands").function(command, args)
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------- ELECTRON ----------------------------------------------------------- //
|
|
|
|
let mainWindow;
|
|
|
|
function createWindow() {
|
|
mainWindow = new electron.BrowserWindow({
|
|
width: 800,
|
|
height: 800,
|
|
webPreferences: {
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
preload: `${mainDir}/electron/main/preload.js`
|
|
}
|
|
});
|
|
|
|
mainWindow.loadFile('./electron/main/index.html');
|
|
}
|
|
|
|
electron.app.whenReady().then(createWindow);
|
|
|
|
|
|
// electron.ipcMain.on("extract", (event, args) => {
|
|
// mapFunctions.get("extraction-video-to-audio").function(args)
|
|
// })
|
|
|
|
// setTimeout(() => {
|
|
// mainWindow.webContents.send("fuck", "worked uwu")
|
|
// }, 5000);
|
|
|
|
electron.ipcMain.handle('get-module-names', async () => {
|
|
let module_array = {
|
|
"ai_modules":[],
|
|
"transcription_modules":[]
|
|
}
|
|
mapFunctions.forEach(e => {
|
|
switch(e.type){
|
|
case "llm":
|
|
module_array.ai_modules.push({"name": e.name, "displayname": e.displayname})
|
|
break;
|
|
case "transcription":
|
|
module_array.transcription_modules.push({"name": e.name, "displayname": e.displayname})
|
|
break;
|
|
}
|
|
})
|
|
// console.log(module_array);
|
|
return module_array
|
|
});
|
|
|
|
|
|
// electron.ipcMain.on("get_modules", async (event, args) => {
|
|
// let module_array = {
|
|
// "ai_modules":[],
|
|
// "transcription_modules":[]
|
|
// }
|
|
// mapFunctions.forEach(e => {
|
|
// switch(e.type){
|
|
// case "llm":
|
|
// module_array.ai_modules.push({"name": e.name, "displayname": e.displayname})
|
|
// break;
|
|
// case "transcription":
|
|
// module_array.transcription_modules.push({"name": e.name, "displayname": e.displayname})
|
|
// break;
|
|
// }
|
|
// })
|
|
// console.log(module_array);
|
|
|
|
// mainWindow.webContents.send("modules", module_array)
|
|
// })
|
|
|
|
|
|
|
|
electron.ipcMain.on("file_submit", async (event, args) => {
|
|
try {
|
|
let curstep = 0
|
|
let totalsteps = 3 + args.document.styles.length
|
|
|
|
if(args.document.styles.length == 0)
|
|
throw new Error("At least one Document Style needed");
|
|
|
|
|
|
console.log(args);
|
|
let audiopath = ""
|
|
let transcriptpath = ""
|
|
|
|
console.log("\n\n Running the Video to Audio Extractor");
|
|
// This code handles the Video to Audio extraction module call
|
|
await mapFunctions.get("module-handler").function(args.video.module, {inputVideoPath: args.video.inputVideoPath, outputType: mapFunctions.get(args.transcription.module).audioformat}).then(resp => {
|
|
console.log(resp);
|
|
audiopath = resp
|
|
curstep++
|
|
mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
|
|
}).catch(err => {
|
|
mainWindow.webContents.send("error", err)
|
|
return
|
|
})
|
|
|
|
|
|
console.log("\n\n Running the Audio to Transcription module");
|
|
// TODO implement transcription module
|
|
// This code handles the Audio to Text transcription module call
|
|
await mapFunctions.get("module-handler").function(args.transcription.module, audiopath).then(resp => {
|
|
console.log(resp);
|
|
transcriptpath = resp
|
|
curstep++
|
|
mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
|
|
}).catch(err => {
|
|
mainWindow.webContents.send("error", err)
|
|
return
|
|
})
|
|
|
|
|
|
console.log("\n\n Running the Transcription Summarizer module");
|
|
// This code summarises the transcript, so that it can be used by an llm
|
|
// await mapFunctions.get("summarize-transcription").function('A:\\programing\\@projects\\video2document\\storage\\transcripts\\IMG_2978.json').then(resp => {
|
|
await mapFunctions.get("summarize-transcription2").function(transcriptpath).then(resp => {
|
|
console.log(resp);
|
|
transcriptpath = resp
|
|
curstep++
|
|
mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
|
|
}).catch(err => {
|
|
mainWindow.webContents.send("error", err)
|
|
return
|
|
})
|
|
|
|
console.log("\n\n Running the LLM module");
|
|
// TODO implement documentation module
|
|
// This code handles the Text to Document processing module call
|
|
for (let i = 0; i < args.document.styles.length; i++) {
|
|
console.log(`\n\n Running the LLM for Document Style ${i+1}`);
|
|
|
|
await mapFunctions.get("module-handler").function(args.document.module, {inputTranscriptPath: transcriptpath, documentTypePath: "./storage/documentType/meetingReport.json", language: "en"}).then(resp => {
|
|
console.log(resp);
|
|
transcriptpath = resp
|
|
curstep++
|
|
mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
|
|
}).catch(err => {
|
|
mainWindow.webContents.send("error", err)
|
|
return
|
|
})
|
|
}
|
|
|
|
// TODO actually implement this functionality
|
|
// Module to get the first few lines for each speaker to send to the frontend
|
|
// await mapFunctions.get("speaker-getter-idfk").function(transcriptpath).then(resp => {
|
|
// console.log(resp);
|
|
// transcriptpath = resp
|
|
// curstep++
|
|
// mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
|
|
|
|
// // {
|
|
// // speakerA: {source: "Pfad zur Audio File"},
|
|
// // speakerB:.....
|
|
// // }
|
|
mainWindow.webContents.send("speakers", {speakerA:"pfad1", speakerB:"pfad2"})
|
|
// }).catch(err => {
|
|
// mainWindow.webContents.send("error", err)
|
|
// return
|
|
// })
|
|
|
|
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
})
|
|
|
|
|
|
|
|
let q =
|
|
{
|
|
video: {
|
|
module: "String", // The name of the module, idk if we ever implement other extraction modules, the default one is extraction-video-to-audio
|
|
inputVideoPath: "String", // See script.js on line 27 for an example of what this should look like
|
|
outputType: "String" // The file format to be used for the audio output file, such as wav, mp3, flac and so on
|
|
},
|
|
transcription:{
|
|
module: "String" // The module name of the transcription model you want to use
|
|
},
|
|
document:{
|
|
module: "String", // The module name of the AI model you want to use to create the document
|
|
styles: [ // An array of all the document styles/prompts you want to have the document be processed with
|
|
{
|
|
prompt: "String",
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
let q1 = {
|
|
"ai_modules": [
|
|
{name:"abc", displayname:"ABC"},
|
|
{name:"qeg", displayname:"aqghegahu"}
|
|
],
|
|
"transcription_modules": [
|
|
{name:"abc", displayname:"ABC"},
|
|
{name:"qeg", displayname:"aqghegahu"}
|
|
]
|
|
}
|