Skip to content
This repository has been archived by the owner on Jun 1, 2019. It is now read-only.

Commit

Permalink
Adding setup verification and information to playground
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
muenzpraeger committed Sep 11, 2017
1 parent e5c7ec7 commit 7eb1b22
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,42 @@
<aura:attribute name="datasetModelsImageClassification" type="List"></aura:attribute>
<aura:attribute name="datasetModelsIntent" type="List"></aura:attribute>
<aura:attribute name="datasetModelsSentiment" type="List"></aura:attribute>
<aura:attribute name="setupComplete" type="Boolean" />
<aura:attribute name="einsteinEmail" type="Boolean" />
<aura:attribute name="einsteinFile" type="Boolean" />
<aura:handler name="waitingEvent" event="c:EventEinsteinWaiting" action="{!c.changeSpinner}" />
<aura:handler name="modelEvent" event="c:EventEinsteinModels" action="{!c.updateModelSelection}" />
<aura:handler name="init" value="{!this}" action="{!c.doInitModels}" />
<aura:handler name="init" value="{!this}" action="{!c.doInitPlayground}" />

<div>
<lightning:tabset>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:info" size="small" /> Introduction
</aura:set>
<c:EinsteinPlaygroundIntroduction />
</lightning:tab>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:preview" size="small" /> Image Classification
</aura:set>
<c:EinsteinImageClassification selectionModels="{! v.datasetModelsImageClassification }" />
</lightning:tab>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:like" size="small" /> Language Sentiment
</aura:set>
<c:EinsteinSentiment selectionModels="{! v.datasetModelsSentiment }" />
</lightning:tab>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:signpost" size="small" /> Language Intent
</aura:set>
<c:EinsteinIntent selectionModels="{! v.datasetModelsIntent }" />
<c:EinsteinPlaygroundIntroduction setupComplete="{!v.setupComplete}" einsteinEmail="{!v.einsteinEmail}" einsteinFile="{!v.einsteinEmail}"
/>
</lightning:tab>
<aura:if isTrue="{!v.setupComplete}">
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:preview" size="small" /> Image Classification
</aura:set>
<c:EinsteinImageClassification selectionModels="{! v.datasetModelsImageClassification }" />
</lightning:tab>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:like" size="small" /> Language Sentiment
</aura:set>
<c:EinsteinSentiment selectionModels="{! v.datasetModelsSentiment }" />
</lightning:tab>
<lightning:tab>
<aura:set attribute="label">
<lightning:icon iconName="utility:signpost" size="small" /> Language Intent
</aura:set>
<c:EinsteinIntent selectionModels="{! v.datasetModelsIntent }" />
</lightning:tab>
</aura:if>
</lightning:tabset>

<aura:if isTrue="{! v.spinnerWaiting }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
updateModelSelection: function(component, event, helper) {
helper.updateModelSelection(component, event);
},
doInitModels: function(component, event, helper) {
doInitPlayground: function(component, event, helper) {
var modelsDefaultImageclassification = [
{ id: "FoodImageClassifier", label: "Pre-Build - Food Image Classifier" },
{
Expand All @@ -27,5 +27,13 @@
{ id: "CommunitySentiment", label: "Pre-Build - Community Sentiment" }
];
component.set("v.datasetModelsSentiment", modelsDefaultSentiment);
var action = component.get("c.validateEinsteinPlatformSetup");
action.setCallback(this, function(a) {
var result = a.getReturnValue();
component.set("v.setupComplete", result.einsteinEmail==true && result.einsteinFile==true);
component.set("v.einsteinEmail", result.einsteinEmail);
component.set("v.einsteinFile", result.einsteinFile);
});
$A.enqueueAction(action);
}
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<aura:component controller="Einstein_PlaygroundController">

<aura:attribute name="firstSection" type="String" /> This Playground is an example showcase for how to use the Einstein Platform Services. It is provided as an <a href="https://github.com/muenzpraeger/salesforce-einstein-platform-apex/blob/master/LICENSE.md"
<aura:attribute name="firstSection" type="String" />
<aura:attribute name="setupComplete" type="Boolean" />
<aura:attribute name="einsteinEmail" type="Boolean" />
<aura:attribute name="einsteinFile" type="Boolean" /> This Playground is an example showcase for how to use the Einstein Platform Services. It is provided as an <a href="https://github.com/muenzpraeger/salesforce-einstein-platform-apex/blob/master/LICENSE.md"
target="_blank">open-source
project AS IS</a>. Use it at your own fun and risk.

<lightning:accordion activeSectionName="Setup">
<lightning:accordionSection name="Setup" label="Setup information">
<ul>
<li>- Set the value for <strong>Einstein EMail</strong> in <i>Setup => Custom Settings => Einstein Settings (via the "Manage" button)</i> for your org to the email address that you've used to sign up for Einstein Platform.</li>
<li>- Store the Einstein Platform file as File in the org. The name must be
<i>einstein_platform</i>.</li>
</ul>
<aura:if isTrue="{!v.setupComplete}">
<div class="success">
Einstein Platform is set up successfully in this org.
</div>
<aura:set attribute="else">
<div class="error">
<ul>
<aura:if isTrue="{!v.einsteinEmail}">
<li>- Set the value for <strong>Einstein EMail</strong> in <i>Setup => Custom Settings => Einstein Settings (via the "Manage" button)</i> for your org to the email address that you've used to sign up for Einstein Platform.</li>
</aura:if>
<aura:if isTrue="{!v.einsteinFile}">
<li>- Store the Einstein Platform file as File in the org. The name must be
<i>einstein_platform</i>.</li>
</aura:if>
</ul>
</div>
</aura:set>
</aura:if>
</lightning:accordionSection>
<lightning:accordionSection name="HowTo" label="Playground How To">
The basic workflow for using the Playground is:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.THIS .error {
color: #CB2929;
font-weight: bold;
}

.THIS .success {
color: #029605;
font-weight: bold;
}
33 changes: 28 additions & 5 deletions force-app/main/default/classes/Einstein_PlaygroundController.cls
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
public class Einstein_PlaygroundController {

public static Einstein_PredictionService service = new Einstein_PredictionService(Einstein_PredictionService.Types.IMAGE);

public static boolean checkEinsteinSetup() {
return false;
}
public static Einstein_PredictionService service;

private static void setType(String dataType) {
if (service==null) {
service = new Einstein_PredictionService(Einstein_PredictionService.Types.IMAGE);
}
if (dataType=='image') {
service.setType(Einstein_PredictionService.Types.IMAGE);
} else if (dataType=='text-intent') {
Expand Down Expand Up @@ -57,23 +56,47 @@ public class Einstein_PlaygroundController {

@AuraEnabled
public static Einstein_PredictionResult predictImageClassification(String modelId, String base64) {
setType('');
service.setType(Einstein_PredictionService.Types.IMAGE);
Einstein_PredictionResult result = service.predictImageBase64(modelId, base64, 0, '');
return result;
}

@AuraEnabled
public static Einstein_PredictionResult predictIntent(String modelId, String phrase) {
setType('');
service.setType(Einstein_PredictionService.Types.INTENT);
Einstein_PredictionResult result = service.predictIntent(modelId, phrase, 0, '');
return result;
}

@AuraEnabled
public static Einstein_PredictionResult predictSentiment(String modelId, String phrase) {
setType('');
service.setType(Einstein_PredictionService.Types.SENTIMENT);
Einstein_PredictionResult result = service.predictSentiment(modelId, phrase, 0, '');
return result;
}

@AuraEnabled
public static Map<String, Boolean> validateEinsteinPlatformSetup() {
Map<String, Boolean> mapSettings = new Map<String, Boolean>();
Einstein_Settings__c settings = Einstein_Settings__c.getOrgDefaults();
if (settings.Einstein_EMail__c == null) {
mapSettings.put('einsteinEmail', false);
} else {
mapSettings.put('einsteinEmail', true);
}
ContentVersion base64Content;
try {
base64Content = [SELECT Title, VersionData FROM ContentVersion where Title='einstein_platform' LIMIT 1];
mapSettings.put('einsteinFile', true);
}
catch (QueryException e) {
mapSettings.put('einsteinFile', false);
}
System.debug('blubber');
return mapSettings;
}

}

0 comments on commit 7eb1b22

Please sign in to comment.