-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
52 lines (41 loc) · 1000 Bytes
/
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
45
46
47
48
49
50
51
52
const express = require('express')
const app = express();
var FastText = require('node-fasttext');
const cors = require('cors');
let config = {
dim: 100,
input: "train.txt",
output: "model"
}
FastText.train("supervised", config, function (success, error) {
if(error) {
console.log(error)
return;
}
console.log(success)
})
app.use(cors())
app.get('/', (req, res) => {
res.sendfile("index.html");
});
app.get('/fasttext/', function(req, res) {
var statement = req.param('statement');
res.send(getFastTextResults(statement));
});
function getFastTextResults(statement) {
//predict returns an array with the input and predictions for best cateogires
FastText.predict(
"model.bin", 3,
[statement],
function (success, error) {
if(error) {
console.log(error)
return;
}
console.log(success)
})
return "success!";
}
app.listen(8000, () => {
console.log('Listening on port 8000!')
});