Frontend / app.py
rojasnath's picture
Upload folder using huggingface_hub
0e5e7c1 verified
import streamlit as st
import pandas as pd
import requests
#Streamlit UI for customer churn prediction
st.title("SuperKart Sales Predictor App")
st.write("This tool predicts store sales revenue based on store and product details. Enter the required information below.")
#Collect user info based on dataset columns
ProductWeight = st.number_input("Product_Weight", min_value= 0.5, max_value= 100.0),
ProductSugarContent = st.selectbox("Product_Sugar_Content",["No Sugar", "Low Sugar", "Regular"])
ProductAllocatedArea = st.number_input("Product_Allocated_Area", min_value=0.001, max_value=0.5),
ProductType = st.selectbox("Product_Type",["Baking Goods", "Breads", "Breakfast", "Canned", "Dairy", "Frozen Foods", "Fruits and Vegetables", "Hard Drinks", "Health and Hygiene", "Household", "Meat", "Seafood", "Snack Foods", "Soft Drinks", "Starchy Foods"]),
ProductMRP = st.number_input("Product_MRP", min_value=5, max_value=500),
StoreID = st.selectbox("Store_Id",["OUT001", "OUT002", "OUT003","OUT004"]),
StoreSize = st.selectbox("Store_Size", ["Small", "Medium", "High"]),
StoreLocationCityType = st.selectbox("Store_Location_City_Type",["Tier 1", "Tier 2", "Tier 3"]),
StoreType = st.selectbox("Store_Type",["Supermarket Type1", "Supermarket Type2", "Grocery Store"]),
StoreEstablishmentYear = st.number_input("Store_Age", min_value=2023, max_value=2027)
#Convert categorical inputs to match model training
store_data = {
'Product_Weight' : ProductWeight,
'Product_Sugar_Content' : ProductSugarContent,
'Product_Allocated_Area' : ProductAllocatedArea,
'Product_Type' : ProductType,
'Product_MRP' : ProductMRP,
'Store_Id' : StoreID,
'Store_Size' : StoreSize,
'Store_Location_City_Type' : StoreLocationCityType,
'Store_Type' : StoreType,
'Store_Age' : StoreEstablishmentYear
}
if st.button("Predict", type='primary'):
response = requests.post("https://rojasnath/Backend.hf.space/predict", json=store_data)
if response.status_code == 200:
result = response.json()
sales_prediction = result['prediction']
st.write(f"Based on the information provided, the forecasted sales revenue for the store is ${sales_prediction:.2f}.")
else:
st.error("Error in API Request")
#Batch Prediction
st.subheader("Batch Prediction")
file = st.file_uploader("Upload a CSV file", type=["csv"])
if file is not None:
if st.button("Predict"):
response = requests.post("https://rojasnath/Backend.hf.space/predict_batch", files={"file": file})
if response.status_code == 200:
result = response.json()
st.header("Bacth Prediction Results")
st.write(result)
else:
st.error("Error in API Request")