Create Python apps with IBM Watson and IBM Bluemix
This course is for Python developers who want to learn more about IBM Bluemix and Watson cognitive services. The labs in this course show you how to develop Python applications in both the Flask and Django web frameworks.
IBM Bluemix and Python applications
To create cloud applications in Python, you can use Python boilerplates or runtimes in IBM Bluemix. You can modify that code locally in your own environment and push it back to Bluemix.
Lab 1 overview
This lab shows you how to create your first Python and Django application on IBM® Bluemix® that consumes Watson services. You’ll need a working knowledge Python programming.
Decide on your Python and Cloud Foundry Stack versions
First, let’s explore the Python runtimes that are available on Bluemix.
Open a web browser and open the Bluemix console on https://console.ng.bluemix.net/.
Create your application project
You will initially create your Django projects and application outside of Bluemix. That way you will have more control over the project structure. You can start from either the flask boilerplate or the Python runtime.
Customize the application
1. Create a manifest.yml file. Put this file in the project directory, which is the directory where your manage.py file is stored.
Install prerequisites for Watson services
You won’t need the Watson services until you start using them, but you should install them now so that you’re ready to use them later.
Push the application to Bluemix
1. Open a command prompt and connect to the appropriate Bluemix data center:
Create the application shell
In this section, you’ll use the Watson Language Translation service to detect the language. This simple use case will show you how to get started with the watson-developer-cloud Python SDK.
Add the Watson service
You now have your shell application and can add the Watson service.
In Bluemix, add or bind the Watson Language Translation service. You don’t need to restart the application for now.
Lab 1 summary
That’s it. You should have a working application. In a subsequent lab, you will add a REST API intermediary in the Django code between the form and the translation service, primarily to act as a buffer for actions that might take a long time. This buffer will allow the application to further process the response.
Language identification and translation
The Watson Language Translation service provides domain-specific translation for several domains that provide translation for different languages. The current domains are:
Lab 2 overview
This lab shows you how to add Watson services into the Django application that you created in the first lab.
You will create an application that can check which language is being used. In this lab, you will add code that:
Add translation capability to your application
Make all the changes for this step in the view/wl.py file.
Lab 2 summary
You should now have an application that detects language and determines whether it can be translated to English. If the language is detected, the application translates and then classifies the text.
You can use the Natural Language Classifier service in your applications to understand the language of short textual statements and questions, and then predict how best to classify, or process that text.
Lab 3 overview
This lab shows you how to add more Watson services to the Django application that you created in the first two labs.
Build your classifications
Use the Natural Language Classifier toolkit to create your classifications:
Add the Natural Language Classifier to your application
1. Find the credentials for your Natural Language Classifier service on Bluemix.
Import the Natural language classifier service from the Watson Developer Cloud SDK:
Lab 3 summary
You should now have an application that detects a language and determines whether it can translate that language into English.
REST APIs and credential stores
All Watson Developer Cloud services are exposed as REST APIs. This allows them to be readily consumed and incorporated into your applications.
Lab 4 overview
In this lab, you’ll learn how to create a REST API that wraps the hybrid service that you created in the first three labs.
Make your new functionality available as a REST service
Now that you created a function that both translates and classifies, you will make that function available as a REST API.