app.js
1.78 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// call all the required packages
var express = require('express')
var bodyParser= require('body-parser')
var multer = require('multer');
let { PythonShell } = require ( 'python-shell' )
//CREATE EXPRESS APP
var app = express();
app.use(bodyParser.urlencoded({extended: true}))
app.use('/users', express.static('uploads'))
var options = {
mode: 'text',
pythonPath: '',
pythonOptions: ['-u'],
scriptPath: '',
// args: ['value1', 'value2', 'value3'],
encoding: 'utf8'
};
//ROUTES WILL GO HERE
app.get('/',function(req,res){
res.sendFile(__dirname + '/index.html');
});
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
cb(null, "dataset.txt")
}
})
var upload = multer({ storage: storage })
app.post('/uploadfile', upload.single('myFile'), (req, res, next) => {
const file = req.file
if (!file) {
const error = new Error('Please upload a file')
error.httpStatusCode = 400
return next(error)
}
res.send(file)
})
var upload = multer({ storage: storage })
app.get('/makebot', (req, res) => {
res.sendFile(__dirname + '/index.html');
PythonShell.run('createDataset.py', options, (err, results) => {
if (err) throw err;
console.log('results: %j', results);
});
res.send("create Data set")
PythonShell.run('Word2Vec.py', options, (err, results) => {
if (err) throw err;
console.log('results: %j', results);
});
res.send("word to vector")
PythonShell.run('Seq2Seq.py', options, (err, results) => {
if (err) throw err;
console.log('results: %j', results);
res.send("seq 2 seq")
});
})
app.listen(3000, () => console.log('Server started on port 3000'));