app.js 1.78 KB
// 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'));