File size: 2,088 Bytes
fb2492e
2290222
 
fb2492e
 
 
 
2290222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests

# Streamlit UI for Customer Churn Prediction
st.title("Product Sales Prediction App")
st.write("This tool predicts production sales prediction. Enter the required information below.")

# Collect user input based on dataset columns
weight = st.number_input("Product Weight", min_value=1, max_value=99999999)
sugarcontent = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular Sugar", "reg"])
area = st.number_input("Product allocated area", min_value=1, max_value=9999999)
producttype = st.selectbox("Product type", ["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Snack Foods", "Meat", "Household", "Hard Drinks", "Fruits and Vegetables",
"Breads", "Others", "Starchy Foods", Seafood"])
productmrp = st.number_input("Product MRP", min_val=1, max_value=9999999)
year = st.number_input("Store establishment year", min_value=1985, max_val=2024)
storesize = st.selectbox("store size", ["Small", "Medium", "High"])
citytype = st.number_input("City type", ["Tier1", "Tier2", "Tier3"])
storetype = st.selectbox("store type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])

# Convert categorical inputs to match model training
customer_data = {
    'Product Weight': weight
    'Product Sugar Content':sugarcontent,
    'Product allocated area': area,
    'Product Type': producttype,
    'Product MRP': productmrp,
    'Store establishment year': year,
    'store size': storesize,
    'City type': citytype,
    'store type': storetype,
}


if st.button("Predict", type='primary'):
    response = requests.post("https://sp1505-frontend.hf.space/v1/customer", json=customer_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 {CustomerID} is likely to {churn_prediction}.")
    else:
        st.error("Error in API request")