manish72 commited on
Commit
abedde3
·
verified ·
1 Parent(s): 3ff3327

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -93
app.py CHANGED
@@ -1,94 +1,94 @@
1
-
2
- import streamlit as st
3
- import pandas as pd
4
- import joblib
5
-
6
- # Load your trained model
7
- model = joblib.load('models\model2.pkl')
8
-
9
- # Function to predict sales
10
- def predict_sales(input_data):
11
- # Make predictions using the loaded model
12
- sales_prediction = model.predict(input_data)
13
- return sales_prediction
14
-
15
- # Streamlit app
16
- def main():
17
- st.title('Sales Prediction App')
18
-
19
- # Input widgets
20
- PromoInterval = st.selectbox("Promo Interval", ['No Promotion', 'Jan,Apr,Jul,Oct', 'Feb,May,Aug,Nov', 'Mar,Jun,Sept,Dec'])
21
-
22
- # -----------------------------------------------------------------------------------------------
23
- StoreType = st.radio("StoreType", ["Small Shop", "Medium Store", "Large Store", "Hypermarket"])
24
- Assortment = st.radio("Assortment", ["basic", "extra", "extended"])
25
-
26
-
27
- # Encode StateHoliday as 1 for 'Yes' and 0 for 'No' --------------------------------------
28
- StateHoliday = st.radio("State Holiday", ["Yes", "No"])
29
- StateHoliday = 1 if StateHoliday == "Yes" else 0
30
-
31
- SchoolHoliday = st.radio("School Holiday", ["Yes", "No"])
32
- SchoolHoliday = 1 if SchoolHoliday == "Yes" else 0
33
-
34
- Promo = st.radio("Promotion", ["store is participating", "store is not participating"])
35
- Promo = 1 if Promo == "store is participating" else 0
36
- # ----------------------------------------------------------------------------------------
37
-
38
-
39
- Store = st.slider("Store", 1, 1115)
40
- Customers = st.slider("Customers", 0, 7388)
41
- CompetitionDistance = st.slider("Competition Distance", 20, 75860)
42
- CompetitionOpenSinceMonth = st.slider("Competition Open Since Month", 1, 12)
43
- CompetitionOpenSinceYear = st.slider("Competition Open Since Year", 1998, 2015)
44
- # ----------------------------------------------------------------------------------------
45
-
46
- # Store user inputs
47
- input_data = pd.DataFrame({
48
- 'PromoInterval': [PromoInterval],
49
- 'StoreType': [StoreType],
50
- 'Assortment': [Assortment],
51
- 'StateHoliday': [StateHoliday],
52
- 'Store': [Store],
53
- 'Customers': [Customers],
54
- 'Promo': [Promo],
55
- 'SchoolHoliday': [SchoolHoliday],
56
- 'CompetitionDistance': [CompetitionDistance],
57
- 'CompetitionOpenSinceMonth': [CompetitionOpenSinceMonth],
58
- 'CompetitionOpenSinceYear': [CompetitionOpenSinceYear]
59
- })
60
-
61
- # Display input data
62
- st.subheader('Input Data:')
63
- st.write(input_data)
64
-
65
- # Predict sales
66
- # if st.button('Predict Sales'):
67
- # prediction = predict_sales(input_data)
68
- # st.write('Predicted Sales:', prediction)
69
-
70
- if st.button('Predict Sales'):
71
- prediction = predict_sales(input_data)[0]
72
- formatted_prediction = "{:.2f}".format(prediction) # Format prediction to display two decimal points
73
- st.write('Predicted Sales:', formatted_prediction)
74
-
75
-
76
- if __name__ == '__main__':
77
- main()
78
-
79
-
80
-
81
- # Record at index 795018:
82
- # PromoInterval Jan,Apr,Jul,Oct
83
- # StoreType Small Shop
84
- # Assortment basic
85
- # StateHoliday 0
86
- # Store 650
87
- # Customers 636
88
- # Promo 1
89
- # SchoolHoliday 0
90
- # CompetitionDistance 1420
91
- # CompetitionOpenSinceMonth 10
92
- # CompetitionOpenSinceYear 2012
93
- # Sales 6322
94
  # Name: 795018, dtype: object
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+
6
+ # Load your trained model
7
+ model = joblib.load('models\model1.pkl')
8
+
9
+ # Function to predict sales
10
+ def predict_sales(input_data):
11
+ # Make predictions using the loaded model
12
+ sales_prediction = model.predict(input_data)
13
+ return sales_prediction
14
+
15
+ # Streamlit app
16
+ def main():
17
+ st.title('Sales Prediction App')
18
+
19
+ # Input widgets
20
+ PromoInterval = st.selectbox("Promo Interval", ['No Promotion', 'Jan,Apr,Jul,Oct', 'Feb,May,Aug,Nov', 'Mar,Jun,Sept,Dec'])
21
+
22
+ # -----------------------------------------------------------------------------------------------
23
+ StoreType = st.radio("StoreType", ["Small Shop", "Medium Store", "Large Store", "Hypermarket"])
24
+ Assortment = st.radio("Assortment", ["basic", "extra", "extended"])
25
+
26
+
27
+ # Encode StateHoliday as 1 for 'Yes' and 0 for 'No' --------------------------------------
28
+ StateHoliday = st.radio("State Holiday", ["Yes", "No"])
29
+ StateHoliday = 1 if StateHoliday == "Yes" else 0
30
+
31
+ SchoolHoliday = st.radio("School Holiday", ["Yes", "No"])
32
+ SchoolHoliday = 1 if SchoolHoliday == "Yes" else 0
33
+
34
+ Promo = st.radio("Promotion", ["store is participating", "store is not participating"])
35
+ Promo = 1 if Promo == "store is participating" else 0
36
+ # ----------------------------------------------------------------------------------------
37
+
38
+
39
+ Store = st.slider("Store", 1, 1115)
40
+ Customers = st.slider("Customers", 0, 7388)
41
+ CompetitionDistance = st.slider("Competition Distance", 20, 75860)
42
+ CompetitionOpenSinceMonth = st.slider("Competition Open Since Month", 1, 12)
43
+ CompetitionOpenSinceYear = st.slider("Competition Open Since Year", 1998, 2015)
44
+ # ----------------------------------------------------------------------------------------
45
+
46
+ # Store user inputs
47
+ input_data = pd.DataFrame({
48
+ 'PromoInterval': [PromoInterval],
49
+ 'StoreType': [StoreType],
50
+ 'Assortment': [Assortment],
51
+ 'StateHoliday': [StateHoliday],
52
+ 'Store': [Store],
53
+ 'Customers': [Customers],
54
+ 'Promo': [Promo],
55
+ 'SchoolHoliday': [SchoolHoliday],
56
+ 'CompetitionDistance': [CompetitionDistance],
57
+ 'CompetitionOpenSinceMonth': [CompetitionOpenSinceMonth],
58
+ 'CompetitionOpenSinceYear': [CompetitionOpenSinceYear]
59
+ })
60
+
61
+ # Display input data
62
+ st.subheader('Input Data:')
63
+ st.write(input_data)
64
+
65
+ # Predict sales
66
+ # if st.button('Predict Sales'):
67
+ # prediction = predict_sales(input_data)
68
+ # st.write('Predicted Sales:', prediction)
69
+
70
+ if st.button('Predict Sales'):
71
+ prediction = predict_sales(input_data)[0]
72
+ formatted_prediction = "{:.2f}".format(prediction) # Format prediction to display two decimal points
73
+ st.write('Predicted Sales:', formatted_prediction)
74
+
75
+
76
+ if __name__ == '__main__':
77
+ main()
78
+
79
+
80
+
81
+ # Record at index 795018:
82
+ # PromoInterval Jan,Apr,Jul,Oct
83
+ # StoreType Small Shop
84
+ # Assortment basic
85
+ # StateHoliday 0
86
+ # Store 650
87
+ # Customers 636
88
+ # Promo 1
89
+ # SchoolHoliday 0
90
+ # CompetitionDistance 1420
91
+ # CompetitionOpenSinceMonth 10
92
+ # CompetitionOpenSinceYear 2012
93
+ # Sales 6322
94
  # Name: 795018, dtype: object