FrontEnd / app.py
Lokiiparihar's picture
Create app.py
4d8af4f verified
import streamlit as st
import requests
st.set_page_config(page_title="SuperKart Sales Predictor", page_icon="πŸ›’")
st.title("πŸ›’ SuperKart Sales Prediction")
st.markdown("Enter product and store details below to get the predicted sales.")
with st.form("prediction_form"):
Product_Weight = st.number_input("Product Weight", value=12.0)
Product_Sugar_Content = st.selectbox("Sugar Content", [0, 1])
Product_Allocated_Area = st.number_input("Allocated Area", value=0.05)
Product_MRP = st.number_input("Product MRP", value=150.0)
Store_Size = st.selectbox("Store Size", [0, 1, 2])
Store_Location_City_Type = st.selectbox("City Type", [0, 1, 2])
Store_Type = st.selectbox("Store Type", [0, 1, 2, 3])
Store_Age = st.slider("Store Age (years)", 0, 50, 10)
product_types = [
"Product_Type_Breads", "Product_Type_Breakfast", "Product_Type_Canned",
"Product_Type_Dairy", "Product_Type_Frozen_Foods", "Product_Type_Fruits_and_Vegetables",
"Product_Type_Hard_Drinks", "Product_Type_Health_and_Hygiene", "Product_Type_Household",
"Product_Type_Meat", "Product_Type_Others", "Product_Type_Seafood",
"Product_Type_Snack_Foods", "Product_Type_Soft_Drinks", "Product_Type_Starchy_Foods"
]
selected_type = st.selectbox("Product Type", product_types)
submitted = st.form_submit_button("Predict Sales")
if submitted:
input_data = {
"Product_Weight": Product_Weight,
"Product_Sugar_Content": Product_Sugar_Content,
"Product_Allocated_Area": Product_Allocated_Area,
"Product_MRP": Product_MRP,
"Store_Size": Store_Size,
"Store_Location_City_Type": Store_Location_City_Type,
"Store_Type": Store_Type,
"Store_Age": Store_Age
}
for pt in product_types:
input_data[pt] = 1 if pt == selected_type else 0
api_url = "https://lokiiparihar-SuperkartBackendModalDeploy-XGBoost.hf.space/predict" # Replace with actual backend
try:
with st.spinner("Predicting..."):
res = requests.post(api_url, json=input_data)
res.raise_for_status()
st.success(f"βœ… Predicted Sales: {res.json()['prediction']:.2f} units")
except Exception as e:
st.error(f"Prediction failed: {e}")