CoolFace
Apppublic

Adrek28/Creating_Spaces_and_Adding_Secrets_in_Hugging_Face

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py59 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import requests4 5# Streamlit UI for Customer Churn Prediction6st.title("Telecom Customer Churn Prediction App")7st.write("This tool predicts customer churn risk based on their details. Enter the required information below.")8 9# Collect user input based on dataset columns10CustomerID = st.number_input("Customer ID", min_value=10000000, max_value=99999999)11SeniorCitizen = st.selectbox("Senior citizen", ["Yes", "No"])12Partner = st.selectbox("Does the customer have a partner?", ["Yes", "No"])13Dependents = st.selectbox("Does the customer have dependents?", ["Yes", "No"])14PhoneService = st.selectbox("Does the customer have phone service?", ["Yes", "No"])15InternetService = st.selectbox("Type of Internet Service", ["DSL", "Fiber optic", "No"])16Contract = st.selectbox("Type of Contract", ["Month-to-month", "One year", "Two year"])17PaymentMethod = st.selectbox("Payment Method", ["Electronic check", "Mailed check", "Bank transfer", "Credit card"])18tenure = st.number_input("Tenure (Months with the company)", min_value=0, value=12)19MonthlyCharges = st.number_input("Monthly Charges", min_value=0.0, value=50.0)20TotalCharges = st.number_input("Total Charges", min_value=0.0, value=600.0)21 22# Convert categorical inputs to match model training23customer_data = {24    'SeniorCitizen': 1 if SeniorCitizen == "Yes" else 0,25    'Partner':Partner,26    'Dependents': Dependents,27    'tenure': tenure,28    'PhoneService': PhoneService,29    'InternetService': InternetService,30    'Contract': Contract,31    'PaymentMethod': PaymentMethod,32    'MonthlyCharges': MonthlyCharges,33    'TotalCharges': TotalCharges34}35 36 37if st.button("Predict", type='primary'):38    response = requests.post("https://Adrek28-Creating_Spaces_and_Adding_Secrets_in_Hugging_Face.hf.space/v1/customer", json=customer_data)    # enter user name and space name before running the cell39    if response.status_code == 200:40        result = response.json()41        churn_prediction = result["Prediction"]  # Extract only the value42        st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")43    else:44        st.error("Error in API request")45 46# Batch Prediction47st.subheader("Batch Prediction")48 49file = st.file_uploader("Upload CSV file", type=["csv"])50if file is not None:51    if st.button("Predict for Batch", type='primary'):52        response = requests.post("https://Adrek28-Creating_Spaces_and_Adding_Secrets_in_Hugging_Face.hf.space/v1/customerbatch", files={"file": file})    # enter user name and space name before running the cell53        if response.status_code == 200:54            result = response.json()55            st.header("Batch Prediction Results")56            st.write(result)57        else:58            st.error("Error in API request")59