Churn-Predict / app.py
Ajeng's picture
Update app.py
38a3b3a
import streamlit as st
import requests
# Give the Name of the Application
st.title('Prediction Churn of Customer')
# Create Submit Form
with st.form(key='form_parameters'):
t = st.number_input('tenure', min_value=0, step=1, max_value=73)
mc = st.number_input('MonthlyCharges', min_value=18.25, step=0.05,max_value=118.75)
s = st.sidebar.selectbox(label='SeniorCitizen', options=['No', 'Yes'])
p = st.sidebar.selectbox(label='Partner', options=['No', 'Yes'])
d = st.sidebar.selectbox(label='Dependents', options=['No', 'Yes'])
ins = st.sidebar.selectbox(label='InternetService', options=['No','DSL','Fiber optic'])
dp = st.sidebar.selectbox(label='DeviceProtection', options=['Yes','No','Yes'])
stv = st.sidebar.selectbox(label='StreamingTV', options=['No internet service','No','Yes'])
sm = st.sidebar.selectbox(label='StreamingMovies', options=['No internet service','No','Yes'])
con = st.sidebar.selectbox(label='Contract', options=['Month-to-month','One year','Two year'])
pb = st.sidebar.selectbox(label='PaperlessBilling', options=['No', 'Yes'])
pm = st.sidebar.selectbox(label='PaymentMethod', options=['Electronic check','Mailed check','Bank transfer (automatic)','Credit card (automatic)'])
submitted = st.form_submit_button('Predict')
# inference
if submitted:
URL = 'https://churn-predict-ajengnilta.koyeb.app//predict'
param = {'tenure': t,
'MonthlyCharges': mc,
'SeniorCitizen': s,
'Partner': p,
'Dependents': d,
'InternetService': ins,
'DeviceProtection': dp,
'StreamingTV': stv,
'StreamingMovies':sm,
'Contract': con,
'PaperlessBilling': pb,
'PaymentMethod': pm}
r = requests.post(URL, json=param)
if r.status_code == 200:
res = r.json()
st.title('Telco Customer Churn is {}'.format(res['label_names']))
else:
st.title("Unexpected Error")
st.write(r.status_code)