Priyanka-Kumavat-At-TE commited on
Commit
d59bc9a
·
1 Parent(s): e372dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -40
app.py CHANGED
@@ -12,6 +12,7 @@ from sklearn.preprocessing import MinMaxScaler
12
  from tensorflow.keras.models import Sequential
13
  from tensorflow.keras.layers import Dense
14
  import matplotlib.pyplot as plt
 
15
  import pickle
16
 
17
  import warnings
@@ -32,7 +33,8 @@ st.write("""Supply Chain Causal Analysis Model:
32
  into the complex dynamics of supply chain operations, empowering businesses to make data-driven decisions and drive
33
  operational excellence""")
34
 
35
- st.sidebar.header('Supply Chain Data')
 
36
  # loading the save model
37
  model = tf.keras.models.load_model(os.path.join('Weights_Updated','Best_model.tf'), compile=False)
38
 
@@ -44,10 +46,14 @@ with open ('le_product.pkl','rb') as file:
44
  with open ('scaler_scca.pkl','rb') as file1:
45
  scaler = pickle.load(file1)
46
 
47
- # DATA from user
48
  def user_report():
49
- # For Product
50
- Product = st.sidebar.selectbox("Product Name",("Product A", "Product B","Product C","Product D"))
 
 
 
 
51
  if Product=='Product A':
52
  Product=0
53
  elif Product=="Product B":
@@ -55,19 +61,42 @@ def user_report():
55
  elif Product=="Product C":
56
  Product=2
57
  else:
58
- Product=3
 
59
  # For Lead_time
60
- Lead_time = st.sidebar.slider('Lead_time', 1,25,9)
 
 
 
 
61
  # For Demand
62
- Demand = st.sidebar.slider('Demand', 20,182,105)
 
 
 
 
63
  # For In_stock
64
- In_stock = st.sidebar.slider('In_stock', 20,250,219)
 
 
 
 
65
  # For Price
66
- Price = st.sidebar.slider('Price', 10,100,64)
 
 
 
 
67
  # For Advertising
68
- Advertising = st.sidebar.slider('Advertising', 1000,4500,2364)
 
 
 
 
69
  # For Weather
70
- Weather = st.sidebar.slider('Weather', 30,110,71)
 
 
71
 
72
  # Create a DataFrame for the input data
73
  user_report_data = {'Product': [Product],
@@ -77,6 +106,8 @@ def user_report():
77
  'Price': [Price],
78
  'Advertising': [Advertising],
79
  'Weather': [Weather]}
 
 
80
 
81
  # # encoded the Product using loaded product label encoder object
82
  # le_product_encoded = le_product.transform([Product])[0]
@@ -90,7 +121,7 @@ def user_report():
90
 
91
  # Supply Chain Data Details
92
  user_data = user_report()
93
- st.subheader("Supply Chain Data Details")
94
  st.write(user_data)
95
 
96
  # User_function
@@ -111,47 +142,58 @@ def predict_backordered(user_data):
111
  else:
112
  return "Backorders are unlikely to occur."
113
 
114
- # Function calling
 
 
 
 
 
 
 
 
 
 
 
 
115
  y_pred = predict_backordered(user_data)
116
- if st.button("Predict"):
117
  st.subheader(y_pred)
118
 
119
 
120
- st.write("""Features Used:
 
 
 
121
 
122
- The following are the input Varibles from the End user which needs to be enter, and then the application will predict whether
123
- the particular Product has the chances of having Backorder or not.
124
 
125
- 1: Product: Name of the product.
126
 
127
- 2: Lead_time: The average number of days taken to deliver the product after placing the order.
128
 
129
- 3: Demand: The number of units of the product demanded during a specific time period.
 
130
 
131
- 4: In_stock: The number of units of the product currently available in the inventory.
132
 
133
- 5: Price: The selling price of the product.
134
 
135
- 6: Advertising: The amount spent on advertising the product during a specific time period.
136
 
137
- 7: Weather: Weather condition during a specific time period that could affect the demand for the product.
138
 
139
- In a retail scenario, weather could be measured in terms of temperature in Fahrenheit or Celsius,
140
- and since temperature affects the demand for products such as clothing, food, and beverages. It is also one of the important factor
141
- to be considered for causal analysis of Supply chain management.
142
 
143
- Target Column/Prediction:
144
- Backordered: A binary variable indicating whether the product will be backordered (1) or not (0) during a specific
145
- time period. This is the target variable that we want to predict
146
 
147
- Backorder refers to a situation where a requested item is not immediately available due to insufficient inventory or other factors.
148
- It can impact customer satisfaction, result in delayed deliveries, and potentially lead to revenue loss. Businesses need to manage
149
- backorders effectively by monitoring inventory levels, optimizing supply chain processes, and providing timely updates to customers.
150
- Backorders can also be used strategically as a marketing tactic, but must be handled carefully to avoid customer disappointment and
151
- maintain a positive reputation.
152
 
153
- In short, Backorder is one of the most important factor in terms of supply chain which means when a particular order goes of out of
154
- stock and demand comes for that out of stock product.""")
 
 
 
 
 
155
 
156
 
157
 
@@ -166,7 +208,5 @@ stock and demand comes for that out of stock product.""")
166
  # if st.button("Predict"):
167
  # st.subheader(f"Next Failure is {y_pred} hours ")
168
 
169
- # Test these data
170
  # Product D, 9.0, 105.0, 219.0, 64.0, 2364.0, 71.24 - for this 0 (Backorders are unlikely to occur)
171
- # #predict_backordered('Product C', 5.0, 105.0, 177.0, 38.0, 1598.0, 83.31) - for this 1 (Backorders are likely to occur)
172
-
 
12
  from tensorflow.keras.models import Sequential
13
  from tensorflow.keras.layers import Dense
14
  import matplotlib.pyplot as plt
15
+ import seaborn as sns
16
  import pickle
17
 
18
  import warnings
 
33
  into the complex dynamics of supply chain operations, empowering businesses to make data-driven decisions and drive
34
  operational excellence""")
35
 
36
+ st.sidebar.header('Supply Chain Features')
37
+
38
  # loading the save model
39
  model = tf.keras.models.load_model(os.path.join('Weights_Updated','Best_model.tf'), compile=False)
40
 
 
46
  with open ('scaler_scca.pkl','rb') as file1:
47
  scaler = pickle.load(file1)
48
 
49
+
50
  def user_report():
51
+
52
+ # # For Product
53
+
54
+ st.sidebar.write("**1: Product Name**")
55
+ st.sidebar.write("Name of the Product")
56
+ Product = st.sidebar.selectbox("",("Product A", "Product B","Product C","Product D"))
57
  if Product=='Product A':
58
  Product=0
59
  elif Product=="Product B":
 
61
  elif Product=="Product C":
62
  Product=2
63
  else:
64
+ Product=4
65
+
66
  # For Lead_time
67
+ st.sidebar.write("**2: Lead_time**")
68
+ st.sidebar.write("The average number of days taken to deliver the product after placing the order.")
69
+ Lead_time = st.sidebar.slider('', 1,25,9)
70
+
71
+
72
  # For Demand
73
+ st.sidebar.write("**3: Demand**")
74
+ st.sidebar.write("The number of units of the product demanded during a specific time period.")
75
+ Demand = st.sidebar.slider('', 20,182,105)
76
+
77
+
78
  # For In_stock
79
+ st.sidebar.write("**4: In_stock**")
80
+ st.sidebar.write("The number of units of the product currently available in the inventory.")
81
+ In_stock = st.sidebar.slider('', 20,250,219)
82
+
83
+
84
  # For Price
85
+ st.sidebar.write("**5: Price**")
86
+ st.sidebar.write("The selling price of the product.")
87
+ Price = st.sidebar.slider('', 10,100,64)
88
+
89
+
90
  # For Advertising
91
+ st.sidebar.write("**6: Advertising**")
92
+ st.sidebar.write("The amount spent on advertising the product during a specific time period.")
93
+ Advertising = st.sidebar.slider('', 1000,4500,2364)
94
+
95
+
96
  # For Weather
97
+ st.sidebar.write("**7: Weather**")
98
+ st.sidebar.write("Weather condition during a specific time period that could affect the demand for the product.")
99
+ Weather = st.sidebar.slider('', 30,110,71)
100
 
101
  # Create a DataFrame for the input data
102
  user_report_data = {'Product': [Product],
 
106
  'Price': [Price],
107
  'Advertising': [Advertising],
108
  'Weather': [Weather]}
109
+
110
+
111
 
112
  # # encoded the Product using loaded product label encoder object
113
  # le_product_encoded = le_product.transform([Product])[0]
 
121
 
122
  # Supply Chain Data Details
123
  user_data = user_report()
124
+ st.subheader("Selected Values of Supply Chain Features")
125
  st.write(user_data)
126
 
127
  # User_function
 
142
  else:
143
  return "Backorders are unlikely to occur."
144
 
145
+
146
+ # CSS code for changing color of the button
147
+ st.markdown("""
148
+ <style>
149
+ .stButton button {
150
+ background-color: #668f45;
151
+ color: white;
152
+ }
153
+ </style>
154
+ """, unsafe_allow_html=True)
155
+
156
+
157
+ # predictions
158
  y_pred = predict_backordered(user_data)
159
+ if st.button("Predict Probability of the Product being Backordered"):
160
  st.subheader(y_pred)
161
 
162
 
163
+ # Display the title
164
+ st.title("Deployment in Real-World Scenarios")
165
+ # Display the title image
166
+ st.image("pasteImg.png", use_column_width=True)
167
 
 
 
168
 
169
+ # background-color: lightgreen; (in CSS)
170
 
171
+ # st.write("""Features Used:
172
 
173
+ # The following are the input Varibles from the End user which needs to be enter, and then the application will predict whether
174
+ # the particular Product has the chances of having Backorder or not.
175
 
176
+ # 1: Product: Name of the product.
177
 
178
+ # 2: Lead_time: The average number of days taken to deliver the product after placing the order.
179
 
180
+ # 3: Demand: The number of units of the product demanded during a specific time period.
181
 
182
+ # 4: In_stock: The number of units of the product currently available in the inventory.
183
 
184
+ # 5: Price: The selling price of the product.
 
 
185
 
186
+ # 6: Advertising: The amount spent on advertising the product during a specific time period.
 
 
187
 
188
+ # 7: Weather: Weather condition during a specific time period that could affect the demand for the product.
 
 
 
 
189
 
190
+ # In a retail scenario, weather could be measured in terms of temperature in Fahrenheit or Celsius,
191
+ # and since temperature affects the demand for products such as clothing, food, and beverages. It is also one of the important factor
192
+ # to be considered for causal analysis of Supply chain management.
193
+
194
+ # Target Column/Prediction:
195
+ # Backordered: A binary variable indicating whether the product will be backordered (1) or not (0) during a specific
196
+ # time period. This is the target variable that we want to predict""")
197
 
198
 
199
 
 
208
  # if st.button("Predict"):
209
  # st.subheader(f"Next Failure is {y_pred} hours ")
210
 
 
211
  # Product D, 9.0, 105.0, 219.0, 64.0, 2364.0, 71.24 - for this 0 (Backorders are unlikely to occur)
212
+ # #predict_backordered('Product C', 5.0, 105.0, 177.0, 38.0, 1598.0, 83.31) - for this 1 (Backorders are likely to occur)