-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (48 loc) · 1.41 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
fs = require("fs"),
multer = require("multer"),
PythonShell = require("python-shell"),
upload = multer({ dest: 'public/tempPics/' });
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static('public'));
app.get("/", function(req, res){
res.render("index");
});
app.post('/upload', upload.single('file'), function(req, res) {
var file = __dirname + '/public/tempPics/' + req.file.filename +".jpg";
fs.rename(req.file.path, file, function(err) {
if (err) {
console.log(err);
res.send(500);
} else {
res.redirect("/displayImage/"+req.file.filename);
}
});
});
app.get("/displayImage/:id", function(req,res){
res.render("displayImage",{picpath: req.params.id});
});
app.get("/result/:id", callPython);
function callPython(req, res) {
var options = {
args:
[
"jblumenstock_2.jpg",
"data/20170511-185253.pb",
"male_full_15v2.pkl"
]
};
PythonShell.run("./python/predict.py", options, function (err, data) {
if (err){
res.send(err);
}
console.log(data);
res.send(data.toString());
});
}
app.listen(process.env.PORT, process.env.IP, function(){
console.log("The 23andCeleb Server Has Started!");
});