Amittripipathi commited on
Commit
c8a84f0
·
verified ·
1 Parent(s): 6214905

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +0 -2
  2. SuperKart_prediction_model_v1_0.joblib +2 -2
  3. app.py +51 -42
  4. requirements.txt +11 -1
Dockerfile CHANGED
@@ -12,5 +12,3 @@ RUN pip3 install -r requirements.txt
12
 
13
  # Define the command to run the Streamlit app on port 8501 and make it accessible externally
14
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
15
-
16
- # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
 
12
 
13
  # Define the command to run the Streamlit app on port 8501 and make it accessible externally
14
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
 
SuperKart_prediction_model_v1_0.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e916470523930ab73e4d8af7ae5333301dd57cb94fe45e7923716a263abc6116
3
- size 197068
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3af9691e3fe153ab300bdca3d9c252d7f6093bf233d4fab7302ff16a9b9d999d
3
+ size 325355
app.py CHANGED
@@ -1,11 +1,18 @@
1
- import requests
2
  import streamlit as st
3
  import pandas as pd
 
 
 
 
 
 
4
 
5
- st.title("SuperKart Sales Prediction")
6
 
7
- # Single Item Prediction
8
- st.subheader("Single Item Prediction")
 
9
 
10
  # Input fields for product and store data based on SuperKart dataset features
11
  product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
@@ -19,43 +26,45 @@ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
19
  store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
20
  store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
21
 
22
- item_data = {
23
- 'Product_Weight': product_weight,
24
- 'Product_Sugar_Content': product_sugar_content,
25
- 'Product_Allocated_Area': product_allocated_area,
26
- 'Product_Type': product_type,
27
- 'Product_MRP': product_mrp,
28
- 'Store_Id': store_id,
29
- 'Store_Establishment_Year': store_establishment_year,
30
- 'Store_Size': store_size,
31
- 'Store_Location_City_Type': store_location_city_type,
32
- 'Store_Type': store_type,
 
33
  }
34
 
35
- # Replace with your Hugging Face Space URL for the backend
36
- backend_url = "https://Amittripipathi-SuperKart.hf.space"
37
-
38
- if st.button("Predict Sales", type='primary'):
39
- response = requests.post(f"{backend_url}/v1/predict_sale", json=item_data)
40
- if response.status_code == 200:
41
- result = response.json()
42
- predicted_sales = result["Predicted_Sales"]
43
- st.write(f"The predicted sales for this item is: {predicted_sales:.2f}")
44
- else:
45
- st.error(f"Error in API request: {response.status_code} - {response.text}")
46
-
47
- # Batch Prediction
48
- st.subheader("Batch Prediction")
49
-
50
- file = st.file_uploader("Upload CSV file for Batch Prediction", type=["csv"])
51
- if file is not None:
52
- if st.button("Predict for Batch", type='primary'):
53
- response = requests.post(f"{backend_url}/v1/predict_sale_batch", files={"file": file})
54
- if response.status_code == 200:
55
- result = response.json()
56
- st.header("Batch Prediction Results")
57
- # Display batch predictions
58
- predictions_df = pd.DataFrame(result['Batch_Predictions'], columns=['Predicted_Sales'])
59
- st.dataframe(predictions_df)
60
- else:
61
- st.error(f"Error in API request: {response.status_code} - {response.text}")
 
 
1
+
2
  import streamlit as st
3
  import pandas as pd
4
+ from datetime import datetime
5
+ import joblib
6
+
7
+ # Load the trained model
8
+ def load_model():
9
+ return joblib.load("SuperKart_sales_prediction_model_v1_0.joblib")
10
 
11
+ model = load_model()
12
 
13
+ # Streamlit UI for Customer Churn Prediction
14
+ st.title("Sales Prediction App")
15
+ st.write("This tool predicts customer Sales details. Enter the required information below.")
16
 
17
  # Input fields for product and store data based on SuperKart dataset features
18
  product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
 
26
  store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
27
  store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
28
 
29
+ # Convert categorical inputs to match model training
30
+ input_data = {
31
+ 'Product_Weight': [product_weight],
32
+ 'Product_Sugar_Content': [product_sugar_content],
33
+ 'Product_Allocated_Area': [product_allocated_area],
34
+ 'Product_Type': [product_type],
35
+ 'Product_MRP': [product_mrp],
36
+ 'Store_Id': [store_id],
37
+ 'Store_Establishment_Year': [store_establishment_year],
38
+ 'Store_Size': [store_size],
39
+ 'Store_Location_City_Type': [store_location_city_type],
40
+ 'Store_Type': [store_type],
41
  }
42
 
43
+ # Custom transformer to calculate store age
44
+ class StoreAgeCalculator(BaseEstimator, TransformerMixin):
45
+ def __init__(self):
46
+ self.current_year = datetime.now().year
47
+
48
+ def fit(self, X, y=None):
49
+ return self
50
+
51
+ def transform(self, X):
52
+ X = X.copy()
53
+ X['Store_Age'] = self.current_year - X['Store_Establishment_Year']
54
+ return X.drop(columns=['Store_Establishment_Year'])
55
+
56
+ # Convert the input data to a DataFrame
57
+ input_df = pd.DataFrame(input_data)
58
+
59
+ # Convert categorical columns to category type
60
+ input_df['Product_Sugar_Content'] = input_df['Product_Sugar_Content'].astype('category')
61
+ input_df['Product_Type'] = input_df['Product_Type'].astype('category')
62
+ input_df['Store_Id'] = input_df['Store_Id'].astype('category')
63
+ input_df['Store_Size'] = input_df['Store_Size'].astype('category')
64
+ input_df['Store_Location_City_Type'] = input_df['Store_Location_City_Type'].astype('category')
65
+ input_df['Store_Type'] = input_df['Store_Type'].astype('category')
66
+
67
+ # Make predictions
68
+ if st.button("Predict"):
69
+ predictions = model.predict(input_df)
70
+ st.write(f"Prediction: The customer is likely to **{predictions[0]}**.")
requirements.txt CHANGED
@@ -1,3 +1,13 @@
1
  pandas==2.2.2
2
- requests==2.28.1
 
 
 
 
 
 
 
 
3
  streamlit==1.43.2
 
 
 
1
  pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ Werkzeug==2.2.2
7
+ flask==2.2.2
8
+ gunicorn==20.1.0
9
+ requests==2.32.3
10
+ uvicorn[standard]
11
  streamlit==1.43.2
12
+ huggingface_hub==0.30.1
13
+ seaborn==0.13.2