This Node.js application demonstrates the Visual Recognition service's Similarity Search feature in a sample application.
To see a running instance of the application demo, click here.
For more information about the Similarity Search, see the detailed documentation.
If you want to experiment with modifying the application or use it as a basis for building your own application, you need to deploy it in your own environment. You can then explore the files, make changes, and see how those changes affect the running application. After making modifications, you can deploy your modified version of the application to the Bluemix cloud.
-
You must have a Bluemix account, and your account must have available space for at least 1 application and 1 service. To register for a Bluemix account, go to https://console.ng.bluemix.net/registration/. Your Bluemix console shows your available space.
-
You must have the following prerequisites installed:
- the Node.js runtime (including the npm package manager)
- the Cloud Foundry command-line client
- A Collection ID created in the Visual Recognition service by uploading your own set of images.
- Use GitHub to clone the repository locally
-
Make sure you have logged in to your Bluemix account using Cloud Foundry. For more information, see The Cloud Foundry command-line interface.
-
Create the Visual Recognition service in Bluemix. Note that you can only have one instance of Visual Recognition service free credentials per Bluemix org. If you can't create credentials, check and see if someone else with access to your org has already created them.
cf create-service watson_vision_combined <service_plan> <service_instance>
For example:
cf create-service watson_vision_combined free similarity-search-test-service
-
Create a service key:
cf create-service-key <service_instance> <service_key>
For example:
cf create-service-key similarity-search-test-service similarity-search-test-service-key1
-
Copy the
.env.example
file to a new.env
file. Open this file in a text editor. -
Retrieve the credentials from the service key:
cf service-key <service_instance> <service_key>
For example:
cf service-key similarity-search-test-service similarity-search-test-service-key1
The output from this command is a JSON object, as in this example:
{ "api_key": "5cbc8d343edd2b9d545123405c89028da3d24592", "note": "It may take up to 5 minutes for this key to become active", "url": "https://gateway-a.watsonplatform.net/visual-recognition/api" }
-
In the JSON output, find the value the
api_key
. Paste the value (not including the quotation marks) into theVISUAL_RECOGNITION_API_KEY
in the.env
file:VISUAL_RECOGNITION_API_KEY=5cbc8d343edd2b9d545123405c89028da3d24592
Leave the
.env
file open in your text editor. -
On the next line in
.env
addCOLLECTION_ID=<your collection id>
You will need to create a collection of images in the Visual Recognition service and then upload images to that collection for the demo to work.
Your .env
file should now look like this:
VISUAL_RECOGNITION_API_KEY=5cbc8d343edd2b9d545123405c89028da3d24592
COLLECTION_ID=some_collection_id
-
Install the demo application package into the local Node.js runtime environment:
npm install
-
Start the application:
npm start
The application is now deployed and running on the local system. Go to http://localhost:3000
in your browser to try it out.
This application uses:
- React (15.3.1)
- Express (4.x)
- Browserify (13.x) + Babelify, Reactify, Uglifyify, Minifyify and Watchify
- Gulp
gulp-live-server
(which includes LiveReload for client-side js/css)- SASS
- ui-component library
-
$ gulp js
: Generatesstatic/js/bundle.js
fromclient/app.js
using Browserify. -
$ gulp css
: Generatesstatic/css/main.css
fromclient/stylesheets/main.scss
using SASS. -
$ gulp serve
: Runsjs
andcss
tasks and subsequently starts the Express app (server/index.js
) and installs watchers for front-end and backend file changes.
.
├── Procfile
├── README.md
├── client
│ ├── app.js // React entry point
│ ├── components // React components
│ │ └── index.jsx
│ ├── stylesheets // SASS stylesheets
│ │ └── main.scss
├── gulpfile.js
├── manifest.yml
├── package.json
├── server
│ ├── routes.js // Express routes
│ ├── index.js // Express configuration
│ └── views
│ └── index.ejs
└── static
├── css
│ └── main.css // Generated by SASS
└── js
└── bundle.js // Generated by Browserify
-
The main source of troubleshooting and recovery information is the Bluemix log. To view the log, run the following command:
$ cf logs <application-name> --recent
-
For more details about the Visual Recognition service, see the documentation.
This sample code is licensed under Apache 2.0. Full license text is available in LICENSE.
Find more open source projects on the IBM Github Page.