Last active
August 4, 2017 13:55
-
-
Save afawcett/321750da5c186488d4b2aaead7a2a12c 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
public with sharing class EinsteinAction { | |
public class Prediction { | |
@InvocableVariable | |
public String label; | |
@InvocableVariable | |
public Double probability; | |
} | |
@InvocableMethod(label='Classify the given files' description='Calls the Einsten API to classify the given ContentVersion files.') | |
public static List<EinsteinAction.Prediction> classifyFiles(List<ID> contentVersionIds) { | |
String access_token = new VisionController().getAccessToken(); | |
ContentVersion content = [SELECT Title,VersionData FROM ContentVersion where Id in :contentVersionIds LIMIT 1]; | |
List<EinsteinAction.Prediction> predictions = new List<EinsteinAction.Prediction>(); | |
for(Vision.Prediction vp : Vision.predictBlob(content.VersionData, access_token, 'GeneralImageClassifier')) { | |
EinsteinAction.Prediction p = new EinsteinAction.Prediction(); | |
p.label = vp.label; | |
p.probability = vp.probability; | |
predictions.add(p); | |
break; // Just take the most probable | |
} | |
return predictions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment