-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (42 loc) · 1.43 KB
/
Copy pathserver.js
File metadata and controls
67 lines (42 loc) · 1.43 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
const express = require('express')
const app = express()
const bodyParser = require('body-parser');
const PythonConnector = require('./PythonConnector.js');
const path=require("path");
app.use(express.static(path.join(__dirname,"public")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/predict', async function (req, res) {
console.log(req.body);
console.log(req.body.text);
let text=req.body.text;
if(text){
console.log('I am the user input...:'+ text);
}
try {
const prediction = await PythonConnector.invoke('predict_from_img', text);
if(prediction){
console.log('I am the user prediction: '+ prediction)
return res.status(200).json({
status:"Chatbot output",
prediction
})
}
}
catch (e) {
console.log(`error in ${req.url}`, e);
res.sendStatus(404);
}
})
// app.get('/', (req, res) => {
// const { spawn } = require('child_process');
// const pyProg = spawn('python', ['./hello.py']);
// pyProg.stdout.on('data', function(data) {
// console.log(data.toString());
// res.write(data);
// res.end('end');
// });
// })
// console.log(process.env.PORT);
const port=process.env.PORT||4000;
app.listen(port, () => console.log('Application listening on port '+ port))