|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import requests |
|
|
|
|
|
|
|
|
st.title("Product Sales Prediction App") |
|
|
st.write("This tool predicts production sales prediction. Enter the required information below.") |
|
|
|
|
|
|
|
|
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") |
|
|
|