vinayakdnrdd commited on
Commit
3adaba2
·
verified ·
1 Parent(s): d8866f0
Files changed (1) hide show
  1. app.py +44 -28
app.py CHANGED
@@ -1,28 +1,44 @@
1
- from flask import Flask, request, jsonify
2
- import joblib
3
- import pandas as pd
4
-
5
- app = Flask(__name__)
6
-
7
- # Load your trained Random Forest model (with preprocessing pipeline)
8
- model = joblib.load('final_rf_model.pkl')
9
-
10
- @app.route('/')
11
- def home():
12
- return "SuperKart Sales Prediction API is running!"
13
-
14
- @app.route('/predict', methods=['POST'])
15
- def predict():
16
- try:
17
- data = request.json # Get data as JSON
18
- df = pd.DataFrame([data]) # Convert to DataFrame
19
-
20
- # Predict using the pipeline (preprocessing + model)
21
- prediction = model.predict(df)
22
- return jsonify({'prediction': float(prediction[0])})
23
- except Exception as e:
24
- return jsonify({'error': str(e)}), 400
25
-
26
- if __name__ == '__main__':
27
- # Run on port 8010, as per your preference
28
- app.run(host='0.0.0.0', port=8010)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ st.title("SuperKart Sales Revenue Predictor")
6
+
7
+ # Load model
8
+ @st.cache_resource
9
+ def load_model():
10
+ return joblib.load('final_rf_model.pkl')
11
+
12
+ model = load_model()
13
+
14
+ # Define all input fields
15
+ st.header("Enter Product & Store Details:")
16
+ product_weight = st.number_input("Product Weight", min_value=0.0, max_value=50.0, value=12.5)
17
+ product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "High"])
18
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, max_value=1.0, value=0.05)
19
+ product_type = st.selectbox("Product Type", [
20
+ "Fruits and Vegetables", "Snack Foods", "Household", "Dairy", "Baking Goods",
21
+ "Frozen Foods", "Canned", "Soft Drinks", "Breads", "Breakfast", "Health and Hygiene",
22
+ "Meat", "Others", "Seafood", "Starchy Foods", "Hard Drinks"
23
+ ])
24
+ product_mrp = st.number_input("Product MRP", min_value=0.0, max_value=300.0, value=150.0)
25
+ store_establishment_year = st.selectbox("Store Establishment Year", list(range(1987, 2010)))
26
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
27
+ store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
28
+ store_type = st.selectbox("Store Type", ["Supermarket Type2", "Supermarket Type1", "Departmental Store", "Food Mart"])
29
+
30
+ # Predict button
31
+ if st.button("Predict Sales"):
32
+ input_df = pd.DataFrame([{
33
+ "Product_Weight": product_weight,
34
+ "Product_Sugar_Content": product_sugar_content,
35
+ "Product_Allocated_Area": product_allocated_area,
36
+ "Product_Type": product_type,
37
+ "Product_MRP": product_mrp,
38
+ "Store_Establishment_Year": store_establishment_year,
39
+ "Store_Size": store_size,
40
+ "Store_Location_City_Type": store_location_city_type,
41
+ "Store_Type": store_type
42
+ }])
43
+ prediction = model.predict(input_df)[0]
44
+ st.success(f"Predicted Quarterly Sales Revenue: ₹ {prediction:,.2f}")