Spaces:
Sleeping
Sleeping
File size: 2,784 Bytes
3fcc5b1 26df5a7 3fcc5b1 3f4368e 3fcc5b1 6d78c14 3fcc5b1 3f1e31a 3fcc5b1 935efb0 3fcc5b1 17633ad 3fcc5b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import requests
import streamlit as st
import pandas as pd
st.title ("Customer Churn Prediction - Week1")
st.write ("This tool predicts customer churn risk based on their details. Enter the required information below.")
# Collect user input based on dataset columns
CustId = st.text_input ("Customer ID", value="12345")
Age = st.number_input ("Age", min_value=0, max_value=200, value=23)
Partner = st.selectbox ("Does the customer have a partner?", ["Yes", "No"])
Dependents = st.selectbox ("Does the customer have dependents?", ["Yes", "No"])
PhoneService = st.selectbox ("Does the customer have phone service?", ["Yes", "No"])
InternetService = st.selectbox ("Type of Internet Service", ["DSL", "Fiber optic", "No"])
Contract = st.selectbox ("Type of Contract", ["Month-to-month", "One year", "Two year"])
PaymentMethod = st.selectbox ("Payment Method", ["Electronic check", "Mailed check", "Bank transfer", "Credit card"])
Tenure = st.number_input ("Tenure (Months with the company)", min_value=0, value=12)
MonthlyCharges = st.number_input ("Monthly Charges", min_value=0.0, value=50.0)
TotalCharges = st.number_input ("Total Charges", min_value=0.0, value=600.0)
input_data = {
'customerID': CustId,
'SeniorCitizen': 1 if Age > 60 else 0,
'tenure': Tenure,
'MonthlyCharges': MonthlyCharges,
'TotalCharges': TotalCharges,
'Partner': Partner,
'Dependents': "Yes",
'PhoneService': PhoneService,
'InternetService': InternetService,
'Contract': Contract,
'PaymentMethod': PaymentMethod
}
if st.button("Predict", type='primary'):
response = requests.post ("https://harishsohani-CustChurnWeek1BackEnd.hf.space/v1/customer", json=input_data) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json ()
churn_prediction = result ["Prediction"] # Extract only the value
st.write (f"Based on the information provided, the customer with ID {CustId} is likely to {churn_prediction}.")
else:
st.error ("Error in API request -" + str(response.status_code))
# Batch Prediction
st.subheader ("Batch Prediction - Week1")
file = st.file_uploader ("Upload CSV file", type=["csv"])
if file is not None:
if st.button("Predict for Batch", type='primary'):
response = requests.post("https://harishsohani-CustChurnWeek1BackEnd.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
st.header("Batch Prediction Results")
st.write(result)
else:
st.error("Error in API request"+str(response.status_code))
|