Created
October 13, 2016 19:26
-
-
Save samueleresca/715aa0532822afc769d002eb0d18fe67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require("request"); | |
var config = require("./../Helpers/ConfigurationHelper"); | |
exports.describeImage = function _describeImage(url, callback) { | |
var options = { | |
method: 'POST', | |
url: config.CONFIGURATIONS.COMPUTER_VISION_SERVICE.API_URL + "describe/", | |
headers: { | |
'ocp-apim-subscription-key': config.CONFIGURATIONS.COMPUTER_VISION_SERVICE.API_KEY, | |
'content-type': 'application/json' | |
}, | |
body: {url: url}, | |
json: true | |
}; | |
request(options, callback); | |
}; | |
exports.extractCaption = function _extractCaption(bodyMessage) { | |
if (typeof bodyMessage.description === "undefined") return ""; | |
var desc = bodyMessage.description; | |
if (typeof desc.captions !== "undefined" && | |
desc.captions.length > 0) { | |
return desc.captions[0].text; | |
} | |
return "Oops, I can't recognize it :( !"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment