File size: 1,712 Bytes
1384cf7 1413189 1384cf7 1413189 afd0257 1413189 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import streamlit as st
import pandas as pd
import joblib
# Load model and encoders
@st.cache_resource
def load_model_and_data():
model = joblib.load("deployment_files/Quarterly_Sales_Revenue_model_v1_0.joblib")
data = pd.read_csv("/content/drive/MyDrive/SuperKart.csv") # Update with your actual data file path
return model, data
# SuperKart = pd.read_csv("/content/drive/MyDrive/SuperKart.csv")
# Prediction function
def predict_total_sales_by_store(store_ids, df, rf_tuned):
results = []
feature_cols = [
'Product_Id', 'Store_Id', 'Product_Type', 'Product_Sugar_Content',
'Store_Type', 'Store_Location_City_Type', 'Store_Size',
'Product_Weight', 'Product_Allocated_Area', 'Product_MRP',
'Store_Establishment_Year'
]
for store_id in store_ids:
store_df = df[df['Store_Id'] == store_id].copy()
if store_df.empty:
results.append((store_id, 0.0))
continue
X_input = store_df[feature_cols]
predicted_sales = rf_tuned.predict(X_input).sum()
results.append((store_id, round(predicted_sales, 2)))
return results
# Load
rf_tuned, df = load_model_and_data()
# Streamlit UI
st.title("🧾 Predict Total Quarterly Sales per Store")
# Store ID selection
store_ids = st.multiselect("Select Store ID(s)", sorted(df["Store_Id"].unique()))
if st.button("Predict Sales"):
if not store_ids:
st.warning("Please select at least one Store ID.")
else:
results = predict_total_sales_by_store(store_ids, df, rf_tuned)
st.subheader("📊 Predicted Sales:")
for store_id, sales in results:
st.write(f"🛒 Store {store_id}: ${sales:,.2f}")
|