nsa9's picture
Upload folder using huggingface_hub
c5bb67e verified
import streamlit as st
import pandas as pd
import joblib
# MUST be the first Streamlit command
st.set_page_config(page_title="SuperKart Sales Forecast App", layout="centered")
# Load the trained model
@st.cache_resource
def load_model():
return joblib.load("superkart_sales_forecast_model_v1_0.joblib")
model = load_model()
# Streamlit UI
st.title("SuperKart Sales Forecasting App")
st.write("This tool forecasts sales revenue of SuperKart products based on product and store details.")
st.subheader("Enter Product and Store Details")
# Collect user input (aligned with dataset ranges)
product_weight = st.number_input("Product Weight (kg)", min_value=4.0, max_value=22.0, value=12.65, step=0.1)
product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar", "Non-edible"])
product_allocated_area = st.number_input("Allocated Area (ratio)", min_value=0.004, max_value=0.298, value=0.068, step=0.001)
product_type = st.selectbox("Product Type", [
"Fruits and Vegetables", "Snack Foods", "Dairy", "Canned", "Soft Drinks",
"Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods",
"Household", "Seafood", "Starchy Foods", "Meat", "Hard Drinks", "Others"
])
product_mrp = st.number_input("Product MRP", min_value=31.0, max_value=266.0, value=147.0, step=1.0)
store_id = st.selectbox("Store ID", ["OUT001","OUT002","OUT003","OUT004"])
store_establishment_year = st.number_input("Store Establishment Year", min_value=1987, max_value=2025, value=2002, step=1)
store_size = st.selectbox("Store Size", ["High", "Medium", "Low"])
store_location_city_type = st.selectbox("Store City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Food Mart"])
# Input DataFrame with EXACT column names as training
input_data = pd.DataFrame([{
"Product_Weight": product_weight,
"Product_Sugar_Content": product_sugar_content,
"Product_Allocated_Area": product_allocated_area,
"Product_Type": product_type,
"Product_MRP": product_mrp,
"Store_Id": "store_id",
"Store_Establishment_Year": store_establishment_year,
"Store_Size": store_size,
"Store_Location_City_Type": store_location_city_type,
"Store_Type": store_type
}])
# Predict button
if st.button("Forecast Sales"):
prediction = model.predict(input_data)
st.success(f"The forecasted sales revenue is **₹{prediction[0]:,.2f}**")