<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: HolidayJ</title>
    <description>The latest articles on DEV Community by HolidayJ (@cutiejbiu).</description>
    <link>https://dev.to/cutiejbiu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F497065%2Ff15d40ae-918c-4905-959a-04e7bf4f5800.jpg</url>
      <title>DEV Community: HolidayJ</title>
      <link>https://dev.to/cutiejbiu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cutiejbiu"/>
    <language>en</language>
    <item>
      <title>Share your Dinosaurs</title>
      <dc:creator>HolidayJ</dc:creator>
      <pubDate>Sun, 29 Nov 2020 09:29:10 +0000</pubDate>
      <link>https://dev.to/cutiejbiu/share-your-dinosaurs-4kk9</link>
      <guid>https://dev.to/cutiejbiu/share-your-dinosaurs-4kk9</guid>
      <description>&lt;h1&gt;
  
  
  Every day is an API day: Share your Dinosaurs
&lt;/h1&gt;

&lt;p&gt;WELCOME to Jurassic World! Do your kids love dinosaurs or do you love dinosaurs? This idea is inspired by my teammate's kid who is very into dinosaurs. With the love of a father, we make an API that can make drawing dinosaurs more interesting.&lt;br&gt;
   We are using the latest AI technology to recognize the features of the picture and match it with the dinosaurs in our database.&lt;/p&gt;

&lt;p&gt;Our application has two major functions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Match the drawing with dinosaurs in our database and analyze the ability of the drawing&lt;/li&gt;
&lt;li&gt;See the drawings of others and find friends with similar interest&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The application will show the dinosaur that is most alike to the drawing and analysis its ability and strengths like power, speed, aggressivity, defensive, and intelligence.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2pf9nw0d4lenexfj9lon.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2pf9nw0d4lenexfj9lon.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
  When the users access the page, we may request to access their location and mark it on Google map. The users can check others' drawing and know where the drawing is from.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fusewybxknzdlfp5uz11l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fusewybxknzdlfp5uz11l.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/i_PX_9m0Eho"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  So What we need for this project:
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Anypoint Platform&lt;/li&gt;
&lt;li&gt;Salesforce Developer Org&lt;/li&gt;
&lt;li&gt;Amazon S3 &lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  STEP 1: Set up Salesforce Developer Org
&lt;/h1&gt;

&lt;p&gt;First of all, you need to set up the Einstein Vision api for image classification. For more information about &lt;a href="https://metamind.readme.io/docs/introduction-to-the-einstein-predictive-vision-service" rel="noopener noreferrer"&gt;Einstein Vision api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to set up an account for Einstein Vision Api and get the Access Token. Please follow the step &lt;a href="https://metamind.readme.io/docs/what-you-need-to-call-api" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
After we finished the steps above, we need to create a dataset and train it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating a dataset
&lt;/h2&gt;

&lt;p&gt;You will need to collect at least 10 photos for each category of dinosaurs and save it under the folder with name of dinosaur. &lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxrpopg3e7aohocobl5g6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxrpopg3e7aohocobl5g6.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
When your dataset is ready, zip the file and create dataset using the following CURL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Authorization: Bearer &amp;lt;TOKEN&amp;gt;" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "data=@C:\Data\mountainvsbeach.zip"  https://api.einstein.ai/v1/vision/datasets/upload/sync

curl -X POST -H "Authorization: Bearer &amp;lt;TOKEN&amp;gt;" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "path=http://metamind.io/images/mountainvsbeach.zip"  https://api.einstein.ai/v1/vision/datasets/upload/sync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get the result with Id and then used that Id to train the dataset using the following CURL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Authorization: Bearer &amp;lt;TOKEN&amp;gt;" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "name=Beach Mountain Model" -F "datasetId=57" https://api.einstein.ai/v1/vision/train
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you will get the result with modelId. Please save it and we will use this in our Api Later. &lt;/p&gt;

&lt;h1&gt;
  
  
  STEP 2: Create API
&lt;/h1&gt;

&lt;p&gt;Now it's time to create API. What our API do is &lt;br&gt;
1.Accept the image file Upload&lt;br&gt;
2.Predict the image &lt;br&gt;
3.Store it in S3 and get the presigned URI&lt;br&gt;
4.Get the presigned URI of the photos with the same prediction result&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7jdbnluym23gx5n6n19t.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7jdbnluym23gx5n6n19t.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So there is only one endpoint in our API which is /fileUpload and the RAML is as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#%RAML 1.0
title: Dinosaur Api

/fileUpload:
  post:
    queryParameters:
      name:
        description: children name
        type: string
        required: true
      age:
        description: children age
        type: string
        required: false
      gender:
        type: string
        required: false
      Long:
        description: Location
        type: string
        required: false
      Lad:
        description: Location
        type: string
        required: false
    body:
      multipart/form-data:
        description: The file(s) to be uploaded
    responses:
      200:
        body:
          application/json:
            example:
              output: !include /example.raml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following is the example of responses which include the information of dinosaur, user and friends.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#%RAML 1.0 NamedExample
example:
  {
  "dinosaurs_info": {
    "uploadPhotoURL": "url1",
    "samplePhotoURL": "url2",
    "dinosaurName" : "Tyrannosaurus",
    "sampleDinosaurInfo": {
        "power": 80,
        "speed": 67,
        "attack": 76,
        "defence": 8,
        "Intelligence": 4
      },
    "power": 36,
    "speed": 89,
    "attack": 8,
    "defence": 11,
    "Intelligence": 29
  },
  "user_info": {
    "name": "Yamada Taro",
    "age": "6",
    "location": "lad_long"
  },
  "friend_list": [
    {
    "name": "Taro1",
    "age": "6",
    "location": "lad_long",
    "url":"url1" 
    },
    {
    "name": "Taro2",
    "age": "6",
    "location": "lad_long",
    "url":"url2" 
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The implementation of the flow is like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fah3g60b4c232dokb8cdl.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fah3g60b4c232dokb8cdl.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this flow, instead of using transform message component, we do the transformation directly inside the target component. For example, in the HTTP request component(Predict), we wrote the dataweave directly in the body like below:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa0fe1ws5blniu2h5evmr.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa0fe1ws5blniu2h5evmr.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, reducing the component make the flow look more simple.&lt;/p&gt;

&lt;h3&gt;
  
  
  Details of Implementation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Predict
This is a HTTP request component to make a request to Einstein vision API(/Prediction with Image Base64 String). Because of mime type of the input is Multipart/form-data, I got the content of the input data with payload.parts[0].content and transform it to another Multipart/form-data format data for Einstien Vision API prediction as the capture shown above.For more information about &lt;a href="https://docs.mulesoft.com/mule-runtime/4.3/dataweave-formats-multipart" rel="noopener noreferrer"&gt;Multipart/form-data in Mulesoft&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.Set myVar&lt;br&gt;
I set all the information of user in file name concatenate with underscore and as an object user_info to used in the output.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzanir09mum0k8hor7hhr.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzanir09mum0k8hor7hhr.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.Create object and Create object presigned uri&lt;br&gt;
Uploading the photo to S3 and get the presigned URI, I use the bucket name, I used the property value.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh6722bjlq9p57b6th9ll.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh6722bjlq9p57b6th9ll.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the input data is base64 string, I need to decode it in order to upload it to S3. I also do this directly inside the target component instead of using transform message component.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9362qe877m6zsqn25yqu.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9362qe877m6zsqn25yqu.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I stored the result payload in variables by setting up the target variable on Advanced tab.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhvg4mcpmo2bgwkijjakp.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhvg4mcpmo2bgwkijjakp.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Init friend list and for loop
I create an array List(friendList) and adding value of it by using forEach component with the result of ListObject.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Falp1goe8o78sf4pvsmy6.JPG" alt="Alt Text"&gt;
When uploading photo I stored all the information of the user in the file name by concatenating with underscore and here I want to set the information as an object so I used SplitBy call.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%dw 2.0
import * from dw::core::Strings
output application/json
var friendInfo = substringBeforeLast(payload, ".") splitBy("_")
---
{
    "user_name": friendInfo[1],
    "age" : friendInfo[2],
    "gender" : friendInfo[3],
    "location_Long": friendInfo[4],
    "location_Lad": friendInfo[5],
    "url" : vars.friendPhotoURL
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set up the response value
Final Step is to set up the response value
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%dw 2.0
output application/json
---
{
  "dinosaurs_info": { 
      "uploadPhotoURL" : vars.uploadPhotoURL,
      "samplePhotoURL" : vars.samplePhotoURL,
      "dinosaurName" : vars.response.probabilities[0].label,
      "sampleDinosaurInfo": {
        "power": round(random() * 100),
        "speed": round(random() * 100),
        "attack": round(random() * 100),
        "defence": round(random() * 100),
        "Intelligence": round(random() * 100)
      },
      "power": round(vars.response.probabilities[0].probability * 100),
      "speed": round(random() * 100),
      "attack": round(random() * 100),
      "defence": round(random() * 100),
      "Intelligence": round(random() * 100)
      },
     "user_info": vars.myVar.user_info,
     "friend_list": vars.friendlist
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 3: Set up UI on Salesforce Community Cloud（Experience Cloud）
&lt;/h1&gt;

&lt;p&gt;We used Lightning Web Component for our pages and you can get the code from here: &lt;a href="https://github.com/HninPwintP/MuleHackathon" rel="noopener noreferrer"&gt;salesforceCode&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  About Our team
&lt;/h1&gt;

&lt;p&gt;Keitaro K&lt;br&gt;
Kazutaka U&lt;br&gt;
Takamasa　H&lt;br&gt;
Yun F&lt;br&gt;
Holiday J&lt;/p&gt;

&lt;p&gt;We are salesforce developers in Japan. We started learning Mulesoft this year. We decided to take part in this activity to learn more about this field. After discussing among the team, we decided the above topic because one of our member's children is currently crazy about dinosaurs and we think there are many kids with this interest around the world. By joining this competition, we not only feel accomplished for creating something fun for children, but also gain a bunch of knowledge during the implementation. &lt;/p&gt;

&lt;p&gt;Reference &lt;br&gt;
Dinosaur Api: &lt;a href="https://github.com/HninPwintP/mulesoftHackathon2020/tree/master/dinosaur-api2" rel="noopener noreferrer"&gt;https://github.com/HninPwintP/mulesoftHackathon2020/tree/master/dinosaur-api2&lt;/a&gt;&lt;br&gt;
Salesforce code: &lt;a href="https://github.com/HninPwintP/MuleHackathon" rel="noopener noreferrer"&gt;https://github.com/HninPwintP/MuleHackathon&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mulesofthackathon</category>
      <category>salesforce</category>
      <category>einstionvisionapi</category>
      <category>imageclassification</category>
    </item>
  </channel>
</rss>
