import streamlit as st import pandas as pd import joblib import numpy as np # Load the trained model @st.cache_resource def load_model(): return joblib.load("superkart_sales_prediction_model_v1_0.joblib") model = load_model() # Streamlit UI for Sales Prediction st.title("SuperKart Product Store Sales Prediction App") st.write("This app predicts the Total revenue generated by the sale of a particular product in a particular store.") st.subheader("Enter the product and store details:") # Collect user input for SuperKart features product_weight = st.number_input("Product Weight", min_value=4.0, max_value=22.0, value=12.0) product_allocated_area = st.number_input("Product Allocated Area", min_value=0.004, max_value=0.298, value=0.05) product_mrp = st.number_input("Product MRP", min_value=31.0, max_value=266.0, value=150.0) store_age = st.number_input("Store Age", min_value=16, max_value=38, value=20) # Derived from Store_Establishment_Year product_identifier = st.selectbox("Product Identifier", ["FD", "NC", "DR"]) product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) store_id = st.selectbox("Store ID", ['OUT002', 'OUT003', 'OUT004', 'OUT010', 'OUT013', 'OUT017', 'OUT018', 'OUT019', 'OUT027']) # Assuming these are the store IDs after one-hot encoding store_size = st.selectbox("Store Size", ["High", "Medium", "Small"]) store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"]) # Create a dictionary from user input for prediction user_input_data = { 'Product_Weight': product_weight, 'Product_Allocated_Area': product_allocated_area, 'Product_MRP': product_mrp, 'Store_Age': store_age, 'Product_Identifier': product_identifier, 'Product_Sugar_Content_No Sugar': product_sugar_content == 'No Sugar', 'Product_Sugar_Content_Regular': product_sugar_content == 'Regular', 'Product_Sugar_Content_reg': product_sugar_content == 'reg', # Check if 'reg' is a valid category 'Product_Type_Breads': False, # Placeholder - need to handle Product Type encoding based on user selection 'Product_Type_Breakfast': False, # Placeholder 'Product_Type_Canned': False, # Placeholder 'Product_Type_Dairy': False, # Placeholder 'Product_Type_Frozen Foods': False, # Placeholder 'Product_Type_Fruits and Vegetables': False, # Placeholder 'Product_Type_Hard Drinks': False, # Placeholder 'Product_Type_Health and Hygiene': False, # Placeholder 'Product_Type_Household': False, # Placeholder 'Product_Type_Meat': False, # Placeholder 'Product_Type_Others': False, # Placeholder 'Product_Type_Seafood': False, # Placeholder 'Product_Type_Snack Foods': False, # Placeholder 'Product_Type_Soft Drinks': False, # Placeholder 'Product_Type_Starchy Foods': False, # Placeholder 'Store_Id_OUT002': store_id == 'OUT002', 'Store_Id_OUT003': store_id == 'OUT003', 'Store_Id_OUT004': store_id == 'OUT004', 'Store_Id_OUT010': store_id == 'OUT010', # Assuming OUT010, OUT013, OUT017, OUT018, OUT019, OUT027 are also present in the training data 'Store_Id_OUT013': store_id == 'OUT013', 'Store_Id_OUT017': store_id == 'OUT017', 'Store_Id_OUT018': store_id == 'OUT018', 'Store_Id_OUT019': store_id == 'OUT019', 'Store_Id_OUT027': store_id == 'OUT027', 'Store_Size_Medium': store_size == 'Medium', 'Store_Size_Small': store_size == 'Small', 'Store_Location_City_Type_Tier 2': store_location_city_type == 'Tier 2', 'Store_Location_City_Type_Tier 3': store_location_city_type == 'Tier 3', 'Store_Type_Food Mart': store_type == 'Food Mart', 'Store_Type_Supermarket Type1': store_type == 'Supermarket Type1', 'Store_Type_Supermarket Type2': store_type == 'Supermarket Type2' } # Convert the dictionary to a DataFrame with a single row input_data_df = pd.DataFrame([user_input_data]) # Need to handle Product Type encoding based on user selection and add all expected Product Type columns # This requires knowing all possible Product Types from the training data # Predict button if st.button("Predict"): # Perform prediction prediction = model.predict(input_data_df) # Display the prediction st.write(f"The predicted Product Store Sales Total is: {prediction[0]:.2f}")