Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import pickle | |
| from tensorflow.keras.models import load_model | |
| # Load the Models | |
| with open('final_pipeline.pkl', 'rb') as file_1: | |
| model_pipeline = pickle.load(file_1) | |
| model_ann = load_model('model.h5') | |
| def run(): | |
| st.title('Wine Quality Prediction') | |
| with st.form(key='form_heart_failure'): | |
| user = st.text_input('User ID', max_chars=20) | |
| age = st.number_input('Age', min_value=1, max_value=100, value=25,step=1) | |
| gender = st.selectbox('Are you a male or female?', ('Male','Female')) | |
| region = st.selectbox('In which region do you live?', ('City','Town', 'Village')) | |
| member = st.selectbox('Your level of membership?', ('No Membership', 'Basic Membership', 'Silver Membership', 'Gold Membership', 'Premium Membership', 'Platinum Membership')) | |
| date = st.text_input('Join date', max_chars=10, help='Please enter with yyyy-mm-dd format') | |
| referral = st.selectbox('Did you join using referral codes?', ('Yes','No')) | |
| offer = st.selectbox('What is your preferred offer types?', ('Gift Vouchers/Coupons', 'Credit/Debit Card Offers', 'Without Offers')) | |
| medium = st.selectbox('Which device are you using?', ('Desktop', 'Smartphone', 'Both')) | |
| option = st.selectbox('Which product are you using?', ('Wi-Fi', 'Fiber_Optic', 'Mobile_Data')) | |
| time = st.text_input('Time during last visit to website', max_chars=8, help='Please enter with hh:mm:ss format') | |
| days = st.number_input('Days since last login', min_value=0, max_value=365, value=10, step=1) | |
| tspent = st.number_input('Average Time spent on website', min_value=0., max_value=600., value=30., step=.1) | |
| value = st.number_input('Average Transaction Value', min_value=500., max_value=100000., value=15000., step=.1) | |
| freq = st.number_input('Login Days Frequency', min_value=0, max_value=90, value=10, step=1) | |
| point = st.number_input('Pints received', min_value=0., max_value=2500., value=600., step=.1) | |
| discount = st.selectbox('Did you receive special discount?', ('Yes', 'No')) | |
| preference = st.selectbox('Do you prefer to receive offers?', ('Yes', 'No')) | |
| past = st.selectbox('Have you ever submitted a complaint?', ('Yes', 'No')) | |
| status = st.selectbox('What is the outcome of the comlaints?', ('No Information Available', 'Not Applicable', 'Unsolved', 'Solved', 'Solved in Follow-up'), help='Choose Not Applicable if you have never submitted a complaint') | |
| feedback = st.selectbox('Your feedback for us?', ('Poor Website', 'Poor Customer Service', 'Too many ads', 'Poor Product Quality', 'No reason specified', 'Products always in Stock', 'Reasonable Price', 'Quality Customer Care', 'User Friendly Website')) | |
| submitted = st.form_submit_button('Predict') | |
| data_inf = { | |
| 'user_id': user, | |
| 'age': age, | |
| 'gender': gender, | |
| 'region_category': region, | |
| 'membership_category': member, | |
| 'joining_date': date, | |
| 'joined_through_referral': referral, | |
| 'preferred_offer_types': offer, | |
| 'medium_of_operation': medium, | |
| 'internet_option': option, | |
| 'last_visit_time': time, | |
| 'days_since_last_login' : days, | |
| 'avg_time_spent' : tspent, | |
| 'avg_transaction_value' : value, | |
| 'avg_frequency_login_days' : freq, | |
| 'points_in_wallet' : point, | |
| 'used_special_discount' : discount, | |
| 'offer_application_preference' : preference, | |
| 'past_complaint' : past, | |
| 'complaint_status' : status, | |
| 'feedback' : feedback | |
| } | |
| data_inf = pd.DataFrame([data_inf]) | |
| st.dataframe(data_inf) | |
| data_inf['gender'] = data_inf['gender'].replace({'Male': 'M', 'Female': 'F'}) | |
| if submitted: | |
| # Transform Inference-Set | |
| data_inf_transform = model_pipeline.transform(data_inf) | |
| # Predict using Neural Network | |
| y_pred_inf = model_ann.predict(data_inf_transform) | |
| y_pred_inf = np.where(y_pred_inf >= 0.5, 1, 0) | |
| y_pred_inf = np.where(y_pred_inf == 0, 'No Churn', 'Churn') | |
| st.write('Hasil prediksi Model : ', y_pred_inf) | |
| if __name__ == '__main__': | |
| run() |