import streamlit as st import pandas as pd import numpy as np from tensorflow.keras.models import load_model import datetime import pickle import json # Load All Files with open('final_pipeline.pkl', 'rb') as file_1: final_pipeline = pickle.load(file_1) with open('Drop_Columns.txt', 'r') as file_2: Drop_Columns = json.load(file_2) model_seq2 = load_model('model_seq2.h5') def run(): with st.form(key='Customer_Churn_Prediction'): user_id = st.text_input('ID',value='972706cb0db0068e') age = st.number_input('Age',min_value=0,max_value=99,value=46) gender = st.radio('Gender',('Male','Female')) if gender=='Male': gender='M' else: gender='F' region_category = st.selectbox('Region Category',('Town', 'City','Village')) membership_category = st.selectbox('Membership Category',('Premium Membership','Basic Membership','No Membership', 'Gold Membership','Silver Membership','Platinum Membership')) joining_date = st.date_input('Joining Date',datetime.date(2015,3,27)) joined_through_referral = st.selectbox('Joined Through Referral',('Yes','No')) preferred_offer_types = st.selectbox('Preferred Offer Types',('Credit/Debit Card Offers','Gift Vouchers/Coupons','Without Offers')) medium_of_operation = st.selectbox('Medium of Operation',('Smartphone','Desktop','Both')) internet_option = st.selectbox('Internet Option',('Mobile_Data','Wi-Fi','Fiber_Optic')) last_visit_time = st.text_input('Last Visit Time',value='09:41:40') days_since_last_login = st.number_input('Days Since Last Login',min_value=0,max_value=31,value=16) avg_time_spent = st.number_input('Average Time Spent on the Website',step=0.000001,format="%.6f",min_value=0.000000,max_value=9999.999999,value=1447.387929) avg_transaction_value = st.number_input('Average Transaction Value',step=0.01,format="%.2f",min_value=0.00,max_value=99999.99,value=11839.58) avg_frequency_login_days = st.number_input('Number of Times Login to the Website',min_value=1, max_value=99,value=29) points_in_wallet = st.number_input('Points Balance',step=0.01,format="%.2f",min_value=0.00,max_value=9999.99,value=727.91) used_special_discount = st.selectbox('Uses Special Discount Offered ?',('Yes','No')) offer_application_preference = st.selectbox('Prefer Offers ?',('No','Yes')) past_complaint = st.selectbox(' Has raised any complaints before ?',('No','Yes')) complaint_status = st.selectbox('Were the complaints raised resolved?',('Not Applicable ','Unsolved','Solved','Solved in Follow-up','No Information Available')) feedback = st.text_input('Feedback',value='No reason specified') st.markdown('---') submitted = st.form_submit_button('Are Customers at Risk of Churning ? :thinking_face:') df_inf = { 'user_id': user_id, 'age': age, 'gender': gender, 'region_category': region_category, 'membership_category': membership_category, 'joining_date': joining_date, 'joined_through_referral': joined_through_referral, 'preferred_offer_types': preferred_offer_types, 'medium_of_operation': medium_of_operation, 'internet_option': internet_option, 'last_visit_time':last_visit_time, 'days_since_last_login':days_since_last_login, 'avg_time_spent':avg_time_spent, 'avg_transaction_value':avg_transaction_value, 'avg_frequency_login_days':avg_frequency_login_days, 'points_in_wallet':points_in_wallet, 'used_special_discount':used_special_discount, 'offer_application_preference':offer_application_preference, 'past_complaint':past_complaint, 'complaint_status':complaint_status, 'feedback':feedback } df_inf = pd.DataFrame([df_inf]) # Data Inference df_inf_copy = df_inf.copy() # Removing unnecessary features df_inf_final = df_inf_copy.drop(Drop_Columns,axis=1).sort_index() data_inf_transform = final_pipeline.transform(df_inf_final) st.dataframe(df_inf_final) if submitted: # Predict using Neural Network y_pred_inf = model_seq2.predict(data_inf_transform) st.write('# Are Customers at Risk of Churning ? :thinking_face:') if y_pred_inf == 0: st.subheader('Yes, customers are at risk of churning :disappointed: ') else: st.subheader('No, customers are not at risk of churning :wink:') if __name__ == '__main__': run()