| |
|
| | import streamlit as st |
| | import pandas as pd |
| | import joblib |
| | import numpy as np |
| |
|
| | |
| | st.set_page_config( |
| | page_title="SuperKart Sales Forecaster", |
| | page_icon="π", |
| | layout="wide" |
| | ) |
| | |
| | |
| | @st.cache_resource |
| | def load_model(): |
| | """Loads the serialized model pipeline from disk.""" |
| | |
| | return joblib.load("superkart_prediction_model_v1_0.joblib") |
| |
|
| | |
| | model = load_model() |
| |
|
| |
|
| |
|
| | |
| | st.title("π SuperKart Sales Forecaster") |
| | st.markdown("This application predicts the total sales revenue for a product in a specific store based on its characteristics.") |
| |
|
| | |
| | PRODUCT_TYPES = sorted(['Snack Foods', 'Meat', 'Fruits and Vegetables', 'Household', 'Baking Goods', 'Frozen Foods', 'Dairy', 'Canned', 'Health and Hygiene', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood']) |
| | STORE_TYPES = sorted(['Supermarket Type1', 'Supermarket Type2', 'Departmental Store', 'Food Mart']) |
| | STORE_LOCATIONS = sorted(['Tier 1', 'Tier 2', 'Tier 3']) |
| | SUGAR_CONTENT_OPTIONS = ['Low Sugar', 'Regular'] |
| | STORE_SIZE_OPTIONS = ['Small', 'Medium', 'High'] |
| |
|
| | |
| | with st.form("prediction_form"): |
| | st.header("Enter Product and Store Details") |
| |
|
| | |
| | col1, col2, col3 = st.columns(3) |
| |
|
| | with col1: |
| | st.subheader("Product Details") |
| | product_type = st.selectbox("Product Type", options=PRODUCT_TYPES) |
| | product_weight = st.slider("Product Weight", min_value=4.0, max_value=22.0, value=12.5, step=0.1) |
| | product_sugar_content = st.selectbox("Product Sugar Content", options=SUGAR_CONTENT_OPTIONS) |
| |
|
| | with col2: |
| | st.subheader("Pricing and Display") |
| | product_mrp = st.slider("Product MRP ($)", min_value=30.0, max_value=270.0, value=140.0, step=0.5) |
| | product_allocated_area = st.slider("Product Allocated Area (Ratio)", min_value=0.0, max_value=0.30, value=0.07, step=0.001, format="%.3f") |
| |
|
| | with col3: |
| | st.subheader("Store Details") |
| | store_type = st.selectbox("Store Type", options=STORE_TYPES) |
| | store_size = st.selectbox("Store Size", options=STORE_SIZE_OPTIONS) |
| | store_location_city_type = st.selectbox("Store Location City Type", options=STORE_LOCATIONS) |
| | |
| | store_age = st.slider("Store Age (in years)", min_value=16, max_value=38, value=22, step=1) |
| |
|
| | |
| | submitted = st.form_submit_button("Predict Sales Revenue") |
| |
|
| | |
| | if submitted: |
| | |
| | |
| | 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_Size': store_size, |
| | 'Store_Location_City_Type': store_location_city_type, |
| | 'Store_Type': store_type, |
| | |
| | |
| | 'store_age': store_age |
| | }]) |
| |
|
| | try: |
| | |
| | with st.spinner("Forecasting..."): |
| | prediction = model.predict(input_data) |
| |
|
| | |
| | st.success(f"**Predicted Sales Revenue: ${prediction[0]:,.2f}**") |
| |
|
| | except Exception as e: |
| | st.error(f"An error occurred during prediction: {e}") |
| |
|