Frontend_new / app.py
sp1505's picture
Upload folder using huggingface_hub
8d079e5 verified
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.0)
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", value=100)
year = st.number_input("Store_Establishment_Year", value=2007)
storeid = st.selectbox("Store_Id", ["OUT001", "OUT002", "OUT003", "OUT004"])
storesize = st.selectbox("Store_Size", ["Small", "Medium", "High"])
citytype = st.selectbox("Store_Location_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_Id': storeid,
'Store_Size': storesize,
'Store_Location_City_Type': citytype,
'Store_Type': storetype,
}
if st.button("Predict", type='primary'):
response = requests.post("https://sp1505-backend.hf.space/v1/product", json=customer_data) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
sales_prediction = result["Predicted_Sales"] # Extract only the value
st.write(f"Based on the information provided, the sales is {sales_prediction}.")
else:
st.error("Error in API request")