- To run and test your deployed model through a Python-based user-interface, you need to replace the following information within web-app/app.py.
- Your deployed model's deployment URL, so you can make a POST request.
- An API key which will be used to generate your IBM Cloud IAM token, to authorize yourself.
Generate an IBM Cloud apikey by clicking the Manage --> Access (IAM) option on your top right.
- Click on API keys from the left navigation pane, and select Create an IBM Cloud API key
- Once your key is created Copy or Download your key.
-
Click on your deployed model and under the API reference tab navigate to Python and select the URL to be used in app.py
-
From the command line, type
curl
-V to verify if cURL is installed in your system. If cURL is not installed, refer to these instructions to get it installed -
Execute the following cURL command to generate your access token, but replace the apikey with the apikey you got earlier.
curl -X POST 'https://iam.cloud.ibm.com/oidc/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=<api-key-goes-here>'
-
Install python.org Windows distro 3.8.3 from http://python.org - make sure to add the /python38/scripts folder path to the $PATH environment, if you do not, you will get errors trying to run flask (flask.exe is installed to the scripts folder)
-
Remove powershell alias for curl and install curl from python3.8
PS C:/> remove-item alias:curl
PS C:/> pip3 install curl
- Execute curl to get secure token from IBM IAM. Please note that the token expires after 60 minutes. If you get an internal server error from the main query page (The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application), it may be due to the token expiring. Also note that in powershell the continuation character is ‘
curl -X POST 'https://iam.cloud.ibm.com/oidc/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=<apikey>'
-
Copy and paste the access token into the header in the
web-app/app.py
file. Replace the line" TODO: ADD YOUR IAM ACCESS TOKEN FROM IBM CLOUD HERE"
with your token. -
Modify the
app.py
file within theweb-app
directory to change the POST request with your deployment ID. The finished line should look like this :
You are ready to run the application!
Note, this app is tested on this version of Python 3.8.2
Within the web-app
directory, run the following command:
pip3 install flask flask-wtf urllib3 requests
Next, run the following command to start the flask application.
flask run
- Install flask and dependencies
PS C:/> pip3 install flask flask-wtf urllib3 requests
Verify modules have been installed in the 'python38/scripts' folder
- Run 'web-ap/app.py' from the local directory using flask
PS C:/> set FLASK_APP=app.py
PS C:/> flask run
- Go to
127.0.0.1:5000
in your browser to view the application. Fill in the form, and click on thePredict
to see the predicted charges based on your data.