-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (33 loc) · 1.17 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var express = require("express");
const multer = require('multer');
const spawn = require("child_process").spawn;
const fs = require('fs');
var app = express();
app.get("/",function(request,response){
response.sendFile(__dirname+"/public/index.html");
});
const upload = multer({
storage: multer.diskStorage({
destination: 'uploads',
filename: function(req, file, cb) {
cb(null, file.originalname)
}
})
})
app.post('/upload', upload.single('file'), (req, res, next) => {
const pythonProcess = spawn('python', ["./VisionAPI_Module.py", `./uploads/${req.file.filename}`]);
pythonProcess.stdout.on('data', (data) => {
pythonProcess.kill();
if (data.toString().slice(0,-2) == ""){
res.send("No Face Detected");
} else {
const secondPython = spawn('python', ["./Sentence_Generator_Module.py", data.toString().slice(0,-2), parseInt(req.body.amount)]);
secondPython.stdout.on('data', (finalData) => {
res.send(finalData.toString());
});
}
});
});
app.use(express.static('public'));
app.listen(80);
console.log("displaying at http://localhost:3000");