IBM/watson-second-opinion

Name: watson-second-opinion

Owner: International Business Machines

Description: Get a second opinion on Amazon products by analyzing product reviews with Watson Discovery

Created: 2017-10-20 18:33:03.0

Updated: 2018-05-16 22:10:47.0

Pushed: 2018-05-22 16:32:06.0

Homepage:

Size: 6105

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Create a Review Analyzer with Watson Discovery

In this Code Pattern, we will create a Node.js app that takes the reviews from an online shopping website, Amazon, and feeds them into the Watson Discovery service. The reviews will be stored in a Cloudant or couchdb database. The Watson Discovery service will show the overall sentiments of the reviews. The sample application will do all the reading of reviews for you and will give an overall insight about them. The Code Pattern can be useful to developers that are looking into processing multiple documents with Watson Discovery.

When the reader has completed this Code Pattern, they will understand how to:

Architecture

Flow
  1. The user deploys the app in Kubernetes. The user interacts with the user interface of the app.
  2. The user enters the product ID and the app would start getting the reviews of the Product.
  3. The app then stores the reviews in a database for later use.
  4. The app starts to upload the reviews in Watson Discovery.
  5. After Watson Discovery finishes processing the reviews, the app then stores the result (General Sentiment and Top Entities) in the CouchDB. The user will see the result in the UI.
Included components
Featured technologies
Watch the Video

Prerequisite

Create a Kubernetes cluster with either Minikube for local testing, or with IBM Bluemix Container Service to deploy in cloud. The code here is regularly tested against Kubernetes Cluster from Bluemix Container Service using Travis.

Install Docker by following the instructions here for your preferred operating system.
You would also need a Docker Registry. Docker Hub lets you create one quickly.

Steps

  1. Clone the repo
  2. Create IBM Cloud services
  3. Build your Docker image
  4. Configure deployment files
  5. Deploy the application
  6. Search for a product in Amazon
Deploy to IBM Cloud

Deploy to Bluemix

  1. Create the following service:

  2. Press the above Deploy to IBM Cloud

    The toolchain uses GitHub for its source control. You may be asked to authenticate the toolchain to use your account. The toolchain will clone this repo and will be used for its deployment.

  3. Fill out the following fields.

    • If you don't have an API key for your account, create one here
    • For the cluster name, choose the one you have created
    • For the image registry namespace, use an existing one if you have previously created an IBM Cloud Container Registry or use a unique name for yourself. The toolchain will create one for you if the namespace is existing

      Toolchain will fail if the namespace is taken

    • For the Discovery username and Discovery password, use the one you have just created fields
  4. The IP address of your app can be found in the logs of the delivery pipeline's deploy stage. deploy link

Deploy to Kubernetes
1. Clone the repo
t clone https://github.com/IBM/watson-second-opinion
 watson-second-opinion/
2. Create IBM Cloud services

Create the following service:

3. Build your Docker image

Login to Docker using your username and password for your Docker Registry.

cker login

The Node.js app will be packaged into a Docker image. This will be used by the Kubernetes Cluster.

cker build -t YOUR_DOCKERHUB_USERNAME/watson-review-analyzer:1.0 .
cker push YOUR_DOCKERHUB_USERNAME/watson-review-analyzer:1.0
4. Configure deployment files

Login to IBM Cloud (formerly called Bluemix). If not an IBM employee, use your IBM Cloud account username and password to login

 login

If IBM employee, use –sso option and follow link for one time code, and use it to login.

 login --sso

After you are logged in to IBM Cloud, you should see something like this:

endpoint: https://api.ng.bluemix.net

Time Code (Get one at https://iam-id-2.ng.bluemix.net/identity/passcode)>
enticating...


eted account IBM (d5a44c1--------1a852cef31136c)

eted resource group default


endpoint:     https://api.ng.bluemix.net (API version: 2.92.0)
on:           us-south
:             horea.porutiu@ibm.com
unt:          IBM (d5a44c1--------1a852cef31136c)
urce group:   default

Next, setup kubectl to use your cluster

 cs cluster-config <your-cluster-name>

Use the configuration for your cluster by exporting the environment variables - copy and paste the full line starting with:

port KUBECONFIG=

Add your Watson Discovery credentials in config.json.sample and rename it to config.json:

Discovery Credentials

config.json:


iscoveryUsername" : "YOUR_WATSON_DISCOVERY_USERNAME",
iscoveryPassword" : "YOUR_WATSON_DISCOVERY_PASSWORD"

Create configmap in Kubernetes for config.json

bectl create configmap watson-discovery-config --from-file=config.json

Modify watson-review-analyzer.yaml. In the line where you specify the image name, use the docker image you just built.
Change horeaporutiu/watson-review-analyzer:2.1 to YOUR_DOCKERHUB_USERNAME/watson-review-analyzer:1.0.

    spec:
      containers:
        - image: horeaporutiu/watson-review-analyzer:2.1
          imagePullPolicy: Always
          name: watson-reviews
5. Deploy the application

Deploy the CouchDB database. This is where the reviews and Watson Discovery results will be stored.

bectl apply -f couchdb.yaml

Deploy the Watson Review Analyzer app.

bectl apply -f watson-review-analyzer.yaml

Check if your Pods are running. You should see a couchdb pod and the watson-review-analyzer pod.

bectl get pods

                                         READY     STATUS    RESTARTS   AGE
hdb-deployment-78c87bf5bf-2nhc2          1/1       Running   0          4d
on-reviews-deployment-859b8d454f-4zxkw   1/1       Running   0          4d

You can access the application in the browser via the Load Balancer's IP (External IP). If you don't have the Load Balancer enabled, you can access it through one of your Kubernetes' worker IP and service Node port of watson-review-analyzer.

$ kubectl get service

NAME             CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE
couchdb          172.21.174.52    169.xy.xyz.220   5984:32402/TCP   13d
kubernetes       172.21.0.1       <none>           443/TCP          27d
watson-reviews   172.21.254.246   169.48.xyz.221   80:31385/TCP     15m

If you don't have the Load Balancer and need the worker IP:

$ bx cs workers YOUR_CLUSTER_NAME

OK
ID                                                 Public IP       Private IP       Machine Type   State    Status   Zone    Version
kube-dal12-cr5c30966926aa444f9c02c72d5c3e1ca5-w1   169.xy.xyz.35   10.184.120.196   b2c.16x64      normal   Ready    dal12   1.8.6_1506*

Go to 169.xy.xyz.221 or 169.xy.xyz.35:31385 (for clusters without a Load Balancer)

Landing Page

6. Search for a product in Amazon

To use the app, search for the product you want the reviews to be uploaded to Watson Discovery and get its product ID (ASIN).

https://www.amazon.com/Samsung-Thinnest-Premium-Anti-Scratch-Protective/dp/B06XZ2CM2H/ref=cm_cr_arp_d_product_top?ie=UTF8

In this case, the product ID is B06XZ2CM2H

Landing Page

Go ahead and press Go.

After Watson Discovery finishes processing all the reviews, the app should show you its General Sentiment and Top entities found.

Landing Page

Privacy Notice

Sample Kubernetes Yaml file that includes this package may be configured to track deployments to IBM Cloud and other Kubernetes platforms. The following information is sent to a Deployment Tracker service on each deployment:

This data is collected from the Kubernetes Job in the sample application's yaml file. This data is used by IBM to track metrics around deployments of sample applications to IBM Cloud to measure the usefulness of our examples so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.

Disabling Deployment Tracking

Please comment out/remove the Metric Kubernetes Job portion in the watson-review-analyzer.yaml file.

Links

Learn more

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.