There are times when setting up your application’s server takes more than a reasonable amount of time in your development cycle. With serverless architecuture, you can get away with setting up servers and just running your code. Then you can spend more time programming your application and less time managing your server. A serverless computing platform, despite the name, is actually still using servers to execute your functions. The difference is that you only get charged for how much time it takes your code to run, and you don’t have to worry about paying for idle time. Your functions are run only by events or directly through REST APIs.
This code pattern uses a Cloudant database on IBM Cloud and triggers an action (a Cloud Function) based on changes in the database to classify images that are uploaded. It uses a serverless image recognition web app to showcase the serverless implementation. When the end users upload an image, the executed action gets the image and classifies it using Watson Visual Recognition and then tags the image based on the classifiers it got from the service.
This application demonstrates using Cloud Functions, based on Apache OpenWhisk, to get an image from a Cloudant database and classify it through a Watson Visual Recognition service. The code pattern demonstrates how actions work with data services and execute logic in response to Cloudant events.
One function, or action, is triggered by changes (in this use case, an upload of a document) in a Cloudant database. These documents are piped to another action that submits the image to Watson Visual recognition and uploads a new document in Cloudant with the classifiers produced by Watson.
This code pattern works with the following components:
- Cloud Functions (powered by Apache OpenWhisk): Execute code on demand in a highly scalable, serverless environment.
- Cloudant: Use a fully managed data layer designed for modern web and mobile applications that leverages a flexible JSON schema.
- Watson Visual Recognition: Work with a visual recognition service that understands the contents of images. Visual concepts tag the image, find human faces, approximate age and gender, and find similar images in a collection.
This code pattern shows you how to complete the following tasks:
- Create and deploy Cloud Functions.
- Trigger Cloud Functions with Cloudant changes.
- Use the Watson Image Recognition service with Cloud Functions.
- The user chooses a picture from the gallery.
- The image is stored in the Cloudant database.
- The Cloud Function is triggered when there’s a new image in the database.
- The Cloud Function gets the image and uses Watson Visual Recognition to process the image.
- The Cloud Function stores the results (classes with scores) from the visual recognition in the database.
- The users can see the new tags or classes in the images they uploaded.
Find detailed technical steps for this code pattern in the README.md file in the GitHub repository.
- Clone the repo.
- Create IBM Cloud services.
- Deploy Cloud Functions.
- Start the image recognition app.