-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (36 loc) · 1.13 KB
/
index.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
// Require modules
const express = require("express");
var ejs = require('ejs')
var bodyParser = require('body-parser')
var ps = require('python-shell')
const app = express();
app.set('port', process.env.PORT || 5000)
app.use(require('body-parser').urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.get('/', function(req, res){
//res.render('form', {answer: "", paragraph: "", question: ""});
res.render('form');
})
app.post('/predict',function(req, res){
var mPara = req.body.para;
var mQues = req.body.ques;
// Run Python Script here
let options = {
mode: 'text',
pythonPath: '/usr/bin/python3',
pythonOptions: ['-u'], // get print results in real-time
scriptPath: '.',
args: [mPara, mQues]
};
ps.PythonShell.run('script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
//res.render('form', {answer: results[0], paragraph: mPara, question: mQues})
res.send(results[0])
});
})
//Start server
app.listen(app.get('port'), function() {
console.log('server started.')
})