Download app.py from ABCABCABC999/Quarterly_Sales_Revenue: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/ABCABCABC999/Quarterly_Sales_Revenue/resolve/main/app.py
- Command line
-
hf download hf://ABCABCABC999/Quarterly_Sales_Revenue/app.py
-
curl -L -o app.py https://huggingface.co/ABCABCABC999/Quarterly_Sales_Revenue/resolve/main/app.py
1.71 kB
| import streamlit as st | |
| import pandas as pd | |
| import joblib | |
| # Load model and encoders | |
| 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}") | |