-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (28 loc) · 1.1 KB
/
Copy pathserver.js
File metadata and controls
35 lines (28 loc) · 1.1 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
var express = require('express');
var app = express();
var path = require('path');
app.use(express.urlencoded({
extended: true
}))
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.post('/search', (req, res) => {
const ComputerVisionClient = require('@azure/cognitiveservices-computervision').ComputerVisionClient;
const ApiKeyCredentials = require('@azure/ms-rest-js').ApiKeyCredentials;
const key = '<your-subscription-key';
const endpoint = '<your-endpoint>';
const computerVisionClient = new ComputerVisionClient(
new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': key } }), endpoint
);
const describeURL = req.body.imageURL
console.log('Analyzing URL image to describe...', describeURL.split('/').pop());
const caption = new Promise((resolve) => {
resolve(computerVisionClient.describeImage(describeURL))
})
caption.then((elm) => {
res.json({ response: elm.captions[0].text })
}).catch(err => console.log(err));
})
app.use(express.static('public'))
app.listen(3000);