Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
html-function
public
src
twitter-functions
.browserslistrc
README.md
Staticfile
babel.config.js
manifest.yml
package.json
postcss.config.js
tsconfig.json
tslint.json
vue.config.js.cf.template
vue.config.js.cos.template
vue.config.js.customdomain.template
yarn.lock

README.md

Emotions and Poses Game: Web Application

The web application has been implemented via Vue.js and uses three different TensorFlow.js models to recognize faces, emotions and poses.

In order to train models on the IBM Cloud, read my article Training TensorFlow.js Models with IBM Watson.

The web application can be hosted and run in four different ways:

  • Locally on a developer machine
  • Cloud Foundry Public Application
  • Serverless with Cloud Object Storage
  • Serverless with Cloud Object Storage and Custom Domain

Option 1: Local Setup of the Web Application

In the easiest case the game can be set up on a local machine in less than five minutes. In this case only the game web application is run without being able to register users and having highscores. To set up the game locally, invoke the following commands:

$ git clone https://github.com/IBM/blue-cloud-mirror.git
$ cd blue-cloud-mirror/game
$ yarn install
$ yarn run serve

Invoke http://localhost:8080 in Chrome to launch the application.

Option 2: Deployment to the IBM Cloud

The application can be deployed to the IBM Cloud in two different ways.

  • Cloud Foundry Public Application
  • Serverless application via Cloud Functions and Object Storage

Users and Highscores

In both cases the users API and highscores APIs are optional. If these two components have been set up, the two endpoints are needed.

In local.env define 'API_USERS' and 'API_SCORES'. After this run the following command:

$ scripts/game-configure-apis.sh

Tweets

In order to tweet a picture of the results, additional components need to be set up.

Run the following command to create a new Cloudant service instance. Note that the IBM Cloud lite account only allows one instance. If you have already an instance, define 'CLOUDANT_USERNAME' and 'CLOUDANT_PASSWORD' in local.env.

$ scripts/twitter-setup-cloudant-service.sh

To create the database, run the following command:

$ scripts/twitter-setup-cloudant-database.sh

To create the two OpenWhisk functions and two APIs, run the following command:

$ scripts/twitter-deploy-functions.sh

Option 2a: Deployment to Cloud Foundry

To deploy the web application to Cloud Foundry (as public application), invoke the following command:

$ scripts/game-cloud-foundry.sh

The URL to launch the application (e.g. https://emotions-demo.mybluemix.net) will be displayed as output of the script.

Option 2b: Deployment as Serverless Application

The application can also be deployed as serverless application. The static file resources are stored on IBM Cloud Object Storage.

Note: The IBM Cloud lite plan only allows one Object Storage instance in your organization. If you have already an instance, enter the variable 'COS_ID' in local.env which you can get by invoking the following command:

$ ibmcloud resource service-instance object-storage-emotions

In order to create a new instance, run the following command:

$ scripts/object-storage-create-service.sh

There are two options to deploy the web application as serverless application which have pros and cons.

Option 2b1: Cloud Object Storage

One disadvantage of this option is that the URL will be rather long, e.g. https://s3.us-south.objectstorage.softlayer.net/emotions-demo-niklasheidloffdeibmcom/index.html. Custom domains cannot be used.

Another advantage is that you can only invoke the URL 'https://xxx/index.html'. You can not invoke 'https://xxx/home', 'https://xxx/start', etc. and page reloads don't work.

In order to create a new bucket, run the following command:

$ scripts/object-storage-create-bucket.sh

In order to upload the files, run the following command:

$ scripts/object-storage-upload-files.sh

The URL to launch the application (e.g. https://s3.us-south.objectstorage.softlayer.net/emotions-demo-niklasheidloffdeibmcom/index.html) will be displayed as output of the script.

Option 2b2: Cloud Object Storage and Custom Domain

One advantage of this option is that you can use a custom domain, e.g. https://www.heidloff.eu/demo/game.

Another advantage is that you can open pages like 'https://xxx/start' directly and page reloads work too.

Unfortunately we haven't managed yet to configure CORS for Cloud Object Storage when loading the models. As a result the application will throw CORS errors in the developer console and the levels cannot be played. As a temporary workaround you can install the Chrome CORS extension Allow-Control-Allow-Origin: *.

In order to create a new bucket, run the following command:

$ scripts/object-storage-create-bucket-domain.sh

In order to upload the files, run the following command:

$ scripts/object-storage-upload-files-domain.sh

In order to use a custom domain, IBM Cloud Functions are used. Run the following command to set everything up:

$ scripts/openwhisk-create-html.sh

Open the application in Chrome, e.g. https://www.heidloff.eu/demo/game.

This diagram shows the key components:

alt text