manish72 commited on
Commit
cf21be2
·
verified ·
1 Parent(s): 38d9d16

Update app.py

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