| import streamlit as st |
| import pandas as pd |
| import joblib |
|
|
| |
| @st.cache_resource |
| def load_model(): |
| return joblib.load("t_superkart_sales_prediction_model_v1_0.joblib") |
|
|
| model = load_model() |
|
|
| st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide") |
| st.title("๐ SuperKart Sales Prediction App") |
|
|
| st.write("Fill in the product and store details below to predict sales.") |
|
|
| |
| col1, col2 = st.columns(2) |
|
|
| with col1: |
| product_weight = st.number_input("Product Weight", min_value=0.0, step=0.01) |
| product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, step=0.001) |
| product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.01) |
| product_store_sales_total = st.number_input("Product Store Sales Total", min_value=0.0, step=0.01) |
| store_age = st.number_input("Store Age (Years)", min_value=0, step=1) |
|
|
| with col2: |
| product_sugar_content = st.selectbox("Sugar Content", ["no sugar", "regular"]) |
| product_type = st.selectbox( |
| "Product Type", |
| ["breads", "breakfast", "canned", "dairy", "frozen foods", |
| "fruits and vegetables", "hard drinks", "health and hygiene", |
| "household", "meat", "others", "seafood", "snack foods", |
| "soft drinks", "starchy foods"] |
| ) |
| store_size = st.selectbox("Store Size", ["small", "medium"]) |
| store_location_city_type = st.selectbox("Store Location City Type", ["tier 2", "tier 3"]) |
| store_type = st.selectbox("Store Type", ["food mart", "supermarket type1", "supermarket type2"]) |
| product_group_code = st.selectbox("Product Group Code", ["fd", "nc"]) |
|
|
| |
| input_data = { |
| "Product_Weight": product_weight, |
| "Product_Allocated_Area": product_allocated_area, |
| "Product_MRP": product_mrp, |
| "Product_Store_Sales_Total": product_store_sales_total, |
| "Store_Age": store_age, |
| f"Product_Sugar_Content_{product_sugar_content}": True, |
| f"Product_Type_{product_type}": True, |
| f"Store_Size_{store_size}": True, |
| f"Store_Location_City_Type_{store_location_city_type}": True, |
| f"Store_Type_{store_type}": True, |
| f"Product_Group_Code_{product_group_code}": True |
| } |
|
|
| input_df = pd.DataFrame([input_data]).astype(object) |
|
|
| |
| if hasattr(model, "feature_names_in_"): |
| input_df = input_df.reindex(columns=model.feature_names_in_, fill_value=0) |
|
|
| |
| if st.button("Predict"): |
| try: |
| prediction = model.predict(input_df)[0] |
| st.success(f"Predicted Product Sales: {prediction:.2f}") |
| except Exception as e: |
| st.error(f"Prediction failed: {e}") |
|
|