-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
89 lines (70 loc) · 2.62 KB
/
server.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
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
79
80
81
82
83
84
85
86
87
88
89
var express = require('express');
var serveStatic = require('serve-static');
var bodyParser = require('body-parser');
var app = express();
app.use(serveStatic(__dirname + "/dist"));
const automl = require('@google-cloud/automl');
var projectId = 'medhakcs2020'
var computeRegion = 'us-central1'
var modelId = 'TBL4730066037343518720'
var port = process.env.PORT || 5000;
app.listen(port);
console.log("Running on Port",port)
app.use('/', express.static(__dirname));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Additional middleware which will set headers that we need on each request.
app.use(function (req, res, next) {
// Set permissive CORS header - this allows this server to be used only as
// an API server in conjunction with something like webpack-dev-server.
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,PATCH,POST,DELETE');
// Disable caching so we'll always get the latest comments.
res.setHeader('Cache-Control', 'no-cache');
next();
});
app.get('/api/working', async function (req, res) {
var data = {"working":"2"}
res.json(data)
})
app.post('/api/automl', async function (req, res) {
var inputs = req.body
const client = new automl.v1beta1.PredictionServiceClient();
const payload = {
row: {
values: inputs,
},
};
// payloads = JSON.parse(payload)
// payload.image = {imageBytes: content};
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
// params is additional domain-specific parameters.
// currently there is no additional parameters supported.
const [response] = await client.predict({
name: modelFullId,
payload: payload,
params: { feature_importance: true },
});
console.log('Prediction results:');
count = 0
var score = Number.MIN_VALUE
var disease= ""
response.payload.forEach(result => {
// console.log("stringvalue",result.tables.value.stringValue)
// console.log("score",result.tables.score)
if (score < result.tables.score) {
score = result.tables.score
disease = result.tables.value.stringValue
}
count+=1
// console.log(`Predicted class name: ${result.displayName}`);
// console.log(`Predicted class score: ${result.classification.score}`);
});
data = {}
console.log('count',score)
console.log('disease',disease)
data['score'] = score
data['disease'] = disease
res.json(data)
});