Create an interactive app for business users to consume an ML model in a simple and intuitive way, for example requesting a Chun prediction for one given customer.
This template is for developing a UI to easily consume ML models. By following this template, you can create ML-powered interactive applications that can be easily used by a wide range of business users, and that can deliver real value and insights to end-users.
This tutorial is tailored for the Churn Prediction model, but can be modified to work with other models as well.
from sklearn.feature_extraction.text import TfidfVectorizer
from joblib import load
import pandas as pd
# Loading models to make predictions
model = load('/data_app/model_churn_prediction')
encoder = load('/data_app/encoder_churn_prediction')
The app is designed to allow users to Search records by customer name and obtain churn predictions for a customer. The UI includes a Submit button to get the records and initiate the analysis process.
st.title('Churn Prediction')
st.write("Welcome to Peliqan's Churn Prediction app!")
form = st.form(key='churn-form')
user_input = form.text_input('Search by customer name')
submit = form.form_submit_button('Submit')
Learn more about Streamlit functionality here.
We are applying the user search to find records in an SQL query:
def getRecords(searchTerm):
my_query = f"select * from customers where lower(CustomerName) like lower('{searchTerm}%') limit 5"
dbconn = pq.dbconnect(pq.DW_NAME)
data = dbconn.fetch(pq.DW_NAME, query = my_query)
st.dataframe(data) # show searched results
return data
Now we will define the function makePrediction that takes a user_input parameter as input. It uses a previously trained encoder and model object to predict the Churn probability of customer: