Deploy Machine Learning/Exploratory Data Analysis Models to SAP Business Technology Platform
DISCLAIMER: Please note that the content of this blog post is for demonstration purpose only, it should not be used productively without impact evaluation on production environment.
In this blog, we will implement an end to end solution for Python based web application(Flask) on SAP Business Technology Platform.
- We will use a cloud based HANA DB, and will leverage python package hdbcli to fetch the relevant data using SQL statement.
- We will be using python data science packages such as pandas,seaborn and matplotlib to display various graphs showing Exploratory Data Analysis.
- Node js will be used as a single point of entry to access our Python Application.Python package xssec will be used for authentication.
- Finally we will deploy this application on Launchpad.
*Created for this blog post
- Create a SAP HANA Cloud Database (Service : hana-cloud-trial), below mentioned settings should be enabled:
- Data Source : CO2 and Greenhouse Gas Emissions Country Profiles, we can use the CSV file for uploading in SAP HANA Database Explorer. [ https://ourworldindata.org/co2-and-other-greenhouse-gas-emissions ]
- Github Repo : Machine Learning Model
- Tutorial 1: Import Data into Database using SAP Database Explorer
- Tutorial 2: Connect SAP HANA Database in SAP HANA Cloud to Python
- Tutorial 3: Create a Python Application via Cloud Foundry Command Line Interface
- Tutorial 4: Install the Cloud Foundry Command Line Interface (CLI)
- Tutorial 5: Set Up the Launchpad Service
Above references/links will be used for implementing the complete implementation steps.
Main Part :
- Firstly lets upload the downloaded CSV file(owid-co2-codebook.csv) into SAP HANA Cloud database using Database Explorer as mentioned in above tutorial 1.
- Make country and year as the primary key.
Connecting Python with SAP HANA Cloud:
- Connect to the SAP HANA Cloud DB with the help of tutorial 2.
- Download the GITHUB files from here, for reference purpose.
- Replace the USERNAME,PASSWORD and URL in file env_cloud.json with your instance details.
- URL can be retrieved from Copy SQL Endpoint by removing port number.Provide port number in port field.
- Update manifest.yml file with the application names as per your needs.
- Update requirements.txt with the python packages you want to use while developing the model.
- Update runtime.txt with the python runtime version supported.
Deployment of Application:
- Install CLI with the help of tutorial 4, please note cf.exe file should exist in the same directory as you have manifest.yml file.
- Login to Cloud Foundry using commands cf login or cf login –sso
- Push the extracted and modified folder containing above files using command cf push
- In case of successful push , you will be able to see both the applications running in BTP Cockpit.
- In case of any runtime error in python , error log can be inspected in SAP BTP.
- Application can be opened using application route :
Configure the application on Launchpad:
- Configure the launchpad using tutorial 5 including Application/Catalog and Group.
- Provide application route as per your application in URL:
- Configured application is deployed to the launchpad.
- Application will display a link to the Flask frame-work python Application. We can click on it to display the details as well.
- We can see different graphs showing the correlation between the features.
Congratulations we have finally completed the end to end implementation of application development with SAP Business Technology Platform.
In case of errors do let me know in the comments 🙂
Hi Sourabh Shekhar Sharma!
Thank you providing and describing this example in this blog. I wonder if you have thought about to also use hana-ml library instead of seaborn and matplotlib for exploratory analysis? Any experiences here?
Yes you are right.hana-ml is a powerful and versatile python package for exploratory analysis and there are numerous resources available, however I wanted to provide another perspective in conjunction with currently available resources 🙂
One Additional prerequisite for using hana-ml are the below mentioned roles:(SAP HANA PAL):
Indeed a really nice blog, but I am facing some issue below are some attached errors, I have created my own similar application issue is same now I tried deploying the exact same application of yours, its still the same. Could you please help?
Thank & Regards,
Thanks Hemant, by examining your logs the issue might have occured during DB table creation in HANA.
I can suggest you two things: