Pushpak21 commited on
Commit
42b508d
Β·
verified Β·
1 Parent(s): 02ff0fe

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -4,12 +4,15 @@ import pandas as pd
4
  import requests
5
  import altair as alt
6
 
7
- st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
 
 
8
 
 
9
  st.title("πŸ›’ SuperKart Sales Predictor")
10
  st.markdown("Use the tabs below to predict sales for a single product or upload a CSV file for batch prediction.")
11
 
12
- # Create two tabs
13
  tab1, tab2 = st.tabs(["πŸ” Single Prediction", "πŸ“„ Batch Prediction"])
14
 
15
  # ----------------- Tab 1: Single Prediction -----------------
@@ -38,31 +41,29 @@ with tab1:
38
  ])
39
  est_year = st.slider("Establishment Year", 1987, 2009, 2002)
40
 
41
- # Submit action
42
  if st.button("🎯 Predict Sales 🎯"):
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  try:
44
- payload = {
45
- "Product_Weight": product_weight,
46
- "Product_Allocated_Area": product_allocated_area,
47
- "Product_MRP": product_mrp,
48
- "Product_Sugar_Content": product_sugar_content,
49
- "Product_Type": product_type,
50
- "Store_Id": store_id,
51
- "Store_Size": store_size,
52
- "Store_Location_City_Type": store_location,
53
- "Store_Type": store_type,
54
- "Store_Establishment_Year": est_year
55
- }
56
-
57
- try:
58
- prediction = get_single_prediction(payload)
59
- st.success(f"βœ… Predicted Sales: β‚Ή{prediction:,.2f}")
60
- st.json({**payload, "Predicted_Sales": prediction})
61
- except Exception as e:
62
- st.error(f"⚠️ Error during prediction: {e}")
63
 
64
  # ----------------- Tab 2: Batch Prediction -----------------
65
- # πŸ“„ TAB 2: Batch Prediction
66
  with tab2:
67
  st.subheader("πŸ“„ Upload CSV for Batch Prediction")
68
  uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
@@ -95,5 +96,5 @@ with tab2:
95
  st.dataframe(df)
96
  plot_actual_vs_predicted(df)
97
 
98
- except Exception as e: # βœ… Required block
99
  st.error(f"⚠️ Error while processing the file: {e}")
 
4
  import requests
5
  import altair as alt
6
 
7
+ from predictor.batch_handler import get_predictions, get_single_prediction
8
+ from predictor.utils import reorder_columns, get_csv_download
9
+ from predictor.chart_plotter import plot_actual_vs_predicted
10
 
11
+ st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
12
  st.title("πŸ›’ SuperKart Sales Predictor")
13
  st.markdown("Use the tabs below to predict sales for a single product or upload a CSV file for batch prediction.")
14
 
15
+ # Create tabs
16
  tab1, tab2 = st.tabs(["πŸ” Single Prediction", "πŸ“„ Batch Prediction"])
17
 
18
  # ----------------- Tab 1: Single Prediction -----------------
 
41
  ])
42
  est_year = st.slider("Establishment Year", 1987, 2009, 2002)
43
 
44
+ # Submit button
45
  if st.button("🎯 Predict Sales 🎯"):
46
+ payload = {
47
+ "Product_Weight": product_weight,
48
+ "Product_Allocated_Area": product_allocated_area,
49
+ "Product_MRP": product_mrp,
50
+ "Product_Sugar_Content": product_sugar_content,
51
+ "Product_Type": product_type,
52
+ "Store_Id": store_id,
53
+ "Store_Size": store_size,
54
+ "Store_Location_City_Type": store_location,
55
+ "Store_Type": store_type,
56
+ "Store_Establishment_Year": est_year
57
+ }
58
+
59
  try:
60
+ prediction = get_single_prediction(payload)
61
+ st.success(f"βœ… Predicted Sales: β‚Ή{prediction:,.2f}")
62
+ st.json({**payload, "Predicted_Sales": prediction})
63
+ except Exception as e:
64
+ st.error(f"⚠️ Error during prediction: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  # ----------------- Tab 2: Batch Prediction -----------------
 
67
  with tab2:
68
  st.subheader("πŸ“„ Upload CSV for Batch Prediction")
69
  uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
 
96
  st.dataframe(df)
97
  plot_actual_vs_predicted(df)
98
 
99
+ except Exception as e:
100
  st.error(f"⚠️ Error while processing the file: {e}")