ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Einstein Vision – Real Estate App

Home / Article & Blogs / Salesforce / Lightning / Einstein Vision – Real Estate App
By Pushmitha Babu inLightning, Salesforce, Salesforce Einstein

Let suppose in some real estate website, we search for properties and we get the result related to it. When this comes to salesforces we have Einstein which can help in a large amount of data. Einstein has image classification and object identification as Einstien Vision.

Same way using Einstein Vision a real estate app is built and the scenario is developed where a user can search for a property in Property.com by choosing the type of the house. As the input is given by the user, the related images are displayed to the user. Here we have thousands of images to process it and display it to the user. Where it is difficult manually and can be achieved by some predictive algorithms. In this scenario, Einstein plays a vital role that acts like the human in predicting the images. For more understanding, you can through the trailhead  that provides a managed package that will be useful in this demo (https://trailhead.salesforce.com/en/projects/build-a-cat-rescue-app-that-recognizes-cat-breeds)

Steps to Follow:
  1. AWS
  2. Train Dataset
  3. S3 Link

1. AWS storage is used in two ways. First, storage of images in huge amount inside salesforce is difficult. Hence AWS storage is used where there is no limit to the amount of data to be stored. Second, training Einstein is done with a downloadable zip link in an URL format. In AWS we create a bucket in an S3 storage type where the files are stored in the bucket. Here I have created a zip folder and a common folder. The zip folder is to train the datasets that should be of more than 12MB. The more you add the images, the more Einstein prediction will be accurate. One main thing when you create the files inside AWS is to make the access public to each and every file.

aws

Now the link is ready to train the dataset (https://s3.amazonaws.com/sfdc-einstein-demo/newmodifiedhouses2.zip). The zip folder contains sub-folders as shown below,

subfolder

2. For Einstein, the sub-folder name is a Label and images inside sub-folders are datasets. The created data should be trained by passing the link. After training the data they form models for each dataset labels.

einsteinVision

We pass the URL to apex class on click of the button create a dataset. The file is downloaded to meta-minds where Einstein processes the analysis. To get to know more about meta-minds refer the given link (https://metamind.readme.io/docs/introduction-to-the-einstein-predictive-vision-service).

[sourcecode language=”java”]
//method1 in awsFileTest.apex
@AuraEnabled
public static void createDatasetFromUrl(String zipUrl) {
EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
service.createDatasetFromUrlAsync(zipUrl);
system.debug(service);
}
[/sourcecode]

On refreshing the dataset we get a list of labels and the number of files that we give to train Einstein.

[sourcecode language=”java”]
//method2 in awsFileTest.apex
@AuraEnabled public static List<EinsteinVision_Dataset> getDatasets() {
EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
EinsteinVision_Dataset[] datasets = service.getDatasets();
return datasets;
}
[/sourcecode]

Einstein identifies with dataset models that are done after training the dataset. We can also delete the trained dataset and add a new dataset.

[sourcecode language=”java”]
//method3 in awsFileTest.apex
@AuraEnabled
public static String trainDataset(Decimal datasetId) {
EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
EinsteinVision_Model model = service.trainDataset(Long.valueOf(String.valueOf(datasetId)), ‘Training’, 0, 0, ”);
return model.modelId;
}
//method4 in awsFileTest.apex
@AuraEnabled
public static void deleteDataset(Long datasetId)
{
EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
service.deleteDataset(datasetId);
}
[/sourcecode]

On training the dataset, dataset model with an id is generated.

[sourcecode language=”java”]
public static List<EinsteinVision_Model> getModels(Long datasetId) {
EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
EinsteinVision_Model[] models = service.getModels(datasetId);
return models;
}
[/sourcecode]

3. We use S3 Link app from appExchange to iterate the filenames inside AWS. S3 Link is basically a link between salesforce and AWS. This app helps us to import and export files from AWS whereas importing file means only the details of the file and provides a redirecting link to view or download images. In callout (to AWS) we can only hardcode the destination file name. We have many files that are not possible to hardcode all files names. To install the app follow the guidelines in the given link. (https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3000000CW1OXEA1)

s3 link

Here I make a call out to the AWS on iterating the image name and receiving it as a blog because Einstein needs the actual(*original) image to compare for finding the probability of all possible type of houses.

[sourcecode language=”java”]
@AuraEnabled
public static list<awsFileTestWrapper.awswrapper> getImageAsBlob() {

List<NEILON__File__c> fList = [SELECT Name FROM NEILON__File__c];
system.debug(‘flist ‘+fList);
Map<Blob,String> bList = new Map<Blob,String>();
for(NEILON__File__c nm:fList)
{
Http h = new Http();
HttpRequest req = new HttpRequest();
string firstImageURL = ‘https://s3.amazonaws.com/sfdc-einstein-demo/commonhouses/’+nm.Name;
//Replace any spaces with %20
system.debug(‘firstImageURL’+firstImageURL);
firstImageURL = firstImageURL.replace(‘ ‘, ‘%20’);
req.setEndpoint(firstImageURL);
req.setMethod(‘GET’);
//If you want to get a PDF file the Content Type would be ‘application/pdf’
req.setHeader(‘Content-Type’, ‘image/jpg’);
req.setCompressed(true);
req.setTimeout(60000);

HttpResponse res = null;
res = h.send(req);
//These next three lines can show you the actual response for dealing with error situations
string responseValue = ”;
responseValue = res.getStatus();
system.debug(‘Response Body for File: ‘ + responseValue);
//This is the line that does the magic. We can get the blob of our file. This getBodyAsBlob method was added in the Spring 2012 release and version 24 of the API.
blob image = res.getBodyAsBlob();
system.debug(‘blob’+image);
// bList.add(res.getBodyAsBlob());
bList.put(res.getBodyAsBlob(),nm.Name);
}
system.debug(‘blob list’+bList);

EinsteinVision_PredictionService service = new EinsteinVision_PredictionService();
EinsteinVision_Dataset[] datasets = service.getDatasets();
list<awsFileTestWrapper.awswrapper> listaws=new list<awsFileTestWrapper.awswrapper>();

for (EinsteinVision_Dataset dataset : datasets) {

EinsteinVision_Model[] models = service.getModels(dataset);
EinsteinVision_Model model = models.get(0);
Set<blob> bList2=bList.keySet();
for(Blob fileBlob:bList2)
{
system.debug(‘blob in loop ‘+fileBlob);
EinsteinVision_PredictionResult result = service.predictBlob(model.modelId, fileBlob, ”);
EinsteinVision_Probability probability = result.probabilities.get(0);
system.debug(‘1.’+result.probabilities.get(0).label+’—-‘+result.probabilities.get(0).probability+’ 2.’+result.probabilities.get(1).label+’—-‘+result.probabilities.get(1).probability+
‘ 3.’+result.probabilities.get(2).label+’—-‘+result.probabilities.get(2).probability
+’ 4.’+result.probabilities.get(3).label+’—-‘+result.probabilities.get(3).probability
+’ 5.’+result.probabilities.get(4).label+’—-‘+result.probabilities.get(4).probability);
awsFileTestWrapper.awswrapper aws=new awsFileTestWrapper.awswrapper();
aws.filename=blist.get(fileblob);
//aws.content=fileblob;
aws.mylabel=result.probabilities.get(0).label;
aws.prob=result.probabilities.get(0).probability;
listaws.add(aws);
}
}
System.debug(‘values are’+listaws[0].filename);
return listaws;
}
[/sourcecode]

Einstein gives the result of label and probability related to the image. In result.probabilities.get(0).probability it gives the nearest probability to that particular image. I pass the filename, label, and probability to Lightning component controller. Hence, list of wrappers is used.

[sourcecode language=”java”]
//awsFileTestWrapper.apex
public class awsFileTestWrapper {
public class awswrapper{
@auraenabled public String mylabel;
@auraenabled public String filename;
@auraenabled public double prob;
}
}
[/sourcecode]

In a controller, the callout is made with the iteration of a file name and we are fetching the images from AWS that is displayed to the user.

aura cmp.PNG

The values from apex controller are sent to the javascript.

[sourcecode language=”java”]
//controller.js
({
extractfile: function(component, event, helper) {
alert(‘button clicked’);
var val = component.find(“select”).get(“v.value”);
alert(‘value’+val);
var names=[];
var probs=[];
component.set(“v.IsSpinner”,true);
var action1 = component.get(“c.getImageAsBlob”);
action1.setCallback(this, function(response) {
var ret=response.getReturnValue();
var name=”;
var prob=”;
for(var i=0;i<ret.length;i++){
if(ret[i].mylabel==val){
name=ret[i].filename;
names.push(name);
prob=ret[i].prob;
probs.push(prob);
}
}
component.set(“v.IsSpinner”,false);
component.set(“v.contents”,names);
component.set(“v.probability”,probs);
});
$A.enqueueAction(action1);
},
})
[/sourcecode]

The final output results with images and probability to the user as shown below.

output

Feel free to contact us for any doubts and if you need the code which I have given in the screenshot.

References:
  1. https://developer.salesforce.com/blogs/developer-relations/2017/05/image-based-search-einstein-vision-lightning-components.html
  2. https://andyinthecloud.com/2017/02/05/image-recognition-with-the-salesforce-einstein-api-and-an-amazon-echo/
  3. https://metamind.readme.io/docs/prediction-with-image-file

 

AWSCreate DatasetEinsteinEinstein ModelEinstein VisionImage ClassificationTraining Dataset
146
Like this post
11 Posts
Pushmitha Babu

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostEinstein Sentiment Analysis
  • Next PostHighlights From Spring '18 Release

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

2 Comments

  1. Einstein Intent Analysis Using Einstein Language on Salesforce Chatter – ForceOlympus
    Reply
    27 February 2018
    Reply
  2. Grocery Stock Maintenance Using Einstein Object Detection – ABSYZ
    Reply
    29 May 2018
    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT