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