/einstein-vision-node

Example image recognition web app

Primary LanguageJavaScriptMIT LicenseMIT

Einstein Vision
Image Recognition demo

This Node.js sample app is a modified version of the Einstein Vision Classification Demo app built and maintained by Heroku. That app lets you upload an image to get predictions from the Salesforce Einstein Vision pre-built general classifier model, using the Add-on.

This application is modified slightly, to utilize Salesforce DX and the Salesforce Einstein Playground. The following instructions reflect those modifications. To work directly with the awesome, original app, check out the Heroku repo. NOTE: If you already have an Einstein account and access to a custom model, feel free to skip the Playground setup and model generation steps.

Instructions

In the commands below, terms wrapped in *asterisks* signify places where you'll need to replace the dummy text provided with values matching your Einstein account or Heroku app setup.

  1. Install (and configure) the Einstein Platform Playground in Salesforce. See instructions here.

  2. Using the Playground components, create a model from the dataset at the following URL (or use a dataset of your choice): https://s3-us-west-2.amazonaws.com/ztsfdc-demo-files/einstein-datasets/Cats.zip

  3. Note the Model Id generated by the previous step. This will be the value needed for the CUSTOM_MODEL_ID attribute below.

  4. Clone this repository:

    git clone https://github.com/zaynelt/einstein-vision-node
    cd einstein-vision-node
    
  5. Create a Heroku app, provision add-ons, push source to app:

    heroku create *some_app_name*
    heroku addons:create cloudinary
    git push heroku master
    
  6. Generate RSA text from your Einstein account's PEM file (needed for the PRIVATE_KEY varible in next step) using this site provided by the Einstein team.

  7. Set app variables to use your Einstein account and custom model:

    heroku config:set EINSTEIN_VISION_ACCOUNT_ID=*email@youreinsteinaccount.com* 
    heroku config:set EINSTEIN_VISION_PRIVATE_KEY=*---WHOLE TEXT OF YOUR PRIVATE KEY---*
    heroku config:set EINSTEIN_VISION_URL=https://api.einstein.ai/
    heroku config:set CUSTOM_MODEL_ID=*model_from_step_above*
    
  8. Open your app (& do a brief victory dance):

    heroku open
    

And that's it! If you wish to use change the model you're using, you can re-run the heroku config:set command again, replacing the value for the CUSTOM_MODEL_ID. Or, alternatively, you can change that value (along with any other of the config vars set from the CLI) from the Dashboard UI for your application, under 'Settings'.