muenzpraeger / salesforce-einstein-vision-apex

Apache License 2.0
30 stars 24 forks source link

This repository is deprecated. Please checkout the new wrapper for Salesfore Einstein Platform API that includes image, sentiment and intent prediction.

salesforce-einstein-vision-apex

This repository showcases how to use the Salesforce Einstein Vision API using an Apex based wrapper.

Please check the product documentation for general information about what the Salesforce Einstein Vision API is, how to use it and when it'll be available for you.

Run-On-Your-Own

Prerequisites

For running the app on your own you'll need to fulfill the following requirements:

Please find the detailed instructions for how to setup access to the Einstein Vision API here.

Unmanaged Package

It is recommended to upload the source code to the org of your choice i. e. with the Force.com IDE.

You can also install the current version as an unmanaged package.

Getting started

As this library is basically a wrapper for using the Salesforce Einstein Vision API it is highly recommended to checkout the API documentation.

The workflow for using Einstein Vision can be described with the following scenario.

Please check the MetaMind documentation for recommendations regarding image quality, amount of examples and so forth.

Creating a PredictionService

The foundation for everything is the PredictionService. As the communication with the API is based on a valid OAuth2 token (see MetaMind documentation) you can initiate a new PredictionService in the following way.

EinsteinVision_PredictionService predictionService = new EinsteinVision_PredictionService("AASDFNSADF23423424SADSFASF");

Predict an image

You can predict images either by sending Base64, uploading a Blob or a remote (publicly available!) URL. See this example how to validate a remote URL.

EinsteinVision_PredictionResult result = service.predictUrl(modelId, beachUrl, "");

The returned result will give you an array of all Labels within the Dataset and their probability.

You can find two Lightning examples here in the GitHub repo.

Contribution

Feel free to contribute to this project via pull requests.

License

For licensing see the included license file.