PredictionAPIClient Library with typescript type definitions for node.js and browser.
npm install @azure/cognitiveservices-customvision-predictionThis package contains an isomorphic SDK for PredictionAPIClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
``bash`
npm install @azure/cognitiveservices-customvision-prediction
#### nodejs - Authentication, client creation and classifyImageUrl as an example written in TypeScript.
##### Sample code
The following sample predicts and classifies the given image based on your custom vision training. To know more, refer to the Azure Documentation on Custom Vision Services.
`javascript
const { PredictionAPIClient } = require("@azure/cognitiveservices-customvision-prediction");
const { ApiKeyCredentials } = require("@azure/ms-rest-js");
async function main() {
const customVisionPredictionKey =
process.env["customVisionPredictionKey"] || "
const customVisionPredictionEndPoint =
process.env["customVisionPredictionEndPoint"] ||
"
const projectId = process.env["projectId"] || "
const credentials = new ApiKeyCredentials({ inHeader: {"Prediction-key": customVisionPredictionKey } });
const client = new PredictionAPIClient(credentials, customVisionPredictionEndPoint);
const imageURL =
"https://www.atlantatrails.com/wp-content/uploads/2019/02/north-georgia-waterfalls-1024x683.jpg";
client
.classifyImageUrl(projectId, "Iteration1", { url: imageURL })
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}
main();
`
#### browser - Authentication, client creation and classifyImageUrl as an example written in JavaScript.
##### Sample code
- index.html
`html``