Spaces:
Runtime error
Runtime error
Commit
·
3d06d5d
1
Parent(s):
312261f
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,17 @@ import streamlit as st
|
|
21 |
import os
|
22 |
|
23 |
st.title('Supply Chain Causal Analysis')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
st.sidebar.header('Supply Chain Data')
|
25 |
# loading the save model
|
26 |
model = tf.keras.models.load_model(os.path.join('Weights_Updated','Best_model.tf'), compile=False)
|
@@ -33,4 +44,109 @@ with open ('le_product.pkl','rb') as file:
|
|
33 |
with open ('scaler_scca.pkl','rb') as file1:
|
34 |
scaler = pickle.load(file1)
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
21 |
import os
|
22 |
|
23 |
st.title('Supply Chain Causal Analysis')
|
24 |
+
|
25 |
+
st.write("""Supply Chain Causal Analysis Model:
|
26 |
+
This TensorFlow-powered model utilizes advanced machine learning techniques to analyze and predict causal relationships
|
27 |
+
among key factors in a supply chain, including product demand, lead time, in stock count, pricing, advertising, weather,
|
28 |
+
and backorder status.
|
29 |
+
By uncovering these causal relationships, the model enables businesses to optimize their supply chain operations, reduce costs,
|
30 |
+
and improve customer satisfaction.
|
31 |
+
Developed using TensorFlow, a powerful deep learning framework, this model offers accurate and efficient insights
|
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)
|
|
|
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":
|
54 |
+
Product=1
|
55 |
+
elif Product=="Product C":
|
56 |
+
Product=2
|
57 |
+
else:
|
58 |
+
Product=4
|
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],
|
74 |
+
'Lead_time': [Lead_time],
|
75 |
+
'Demand': [Demand],
|
76 |
+
'In_stock': [In_stock],
|
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]
|
83 |
+
|
84 |
+
# # scaling the input_data using loaded scaler object
|
85 |
+
# report_data = scaler.transform(input_data)
|
86 |
+
|
87 |
+
report_data = pd.DataFrame(user_report_data, index=[0])
|
88 |
+
return report_data
|
89 |
+
|
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
|
97 |
+
def predict_backordered(user_data):
|
98 |
+
|
99 |
+
df = pd.read_csv('Supply_chain_causal_analysis_Synthetic_Dataset_Final.csv')
|
100 |
+
|
101 |
+
# # encoded the Product using loaded product label encoder object
|
102 |
+
# Product = le_product.transform([Product])[0]
|
103 |
+
|
104 |
+
# scaling the input_data using loaded scaler object
|
105 |
+
user_data = scaler.transform(user_data)
|
106 |
+
|
107 |
+
# Make predictions using the pre-trained TensorFlow model
|
108 |
+
predictions = model.predict(user_data)
|
109 |
+
if predictions == 1:
|
110 |
+
return "Backorders are likely to occur."
|
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 |
+
The following are the input Varibles from the End user which needs to be enter, and then the application will predict whether
|
122 |
+
the particular Product has the chances of having Backorder or not.
|
123 |
+
1: Product: Name of the product.
|
124 |
+
2: Lead_time: The average number of days taken to deliver the product after placing the order.
|
125 |
+
3: Demand: The number of units of the product demanded during a specific time period.
|
126 |
+
4: In_stock: The number of units of the product currently available in the inventory.
|
127 |
+
5: Price: The selling price of the product.
|
128 |
+
6: Advertising: The amount spent on advertising the product during a specific time period.
|
129 |
+
7: Weather: Weather condition during a specific time period that could affect the demand for the product.
|
130 |
+
In a retail scenario, weather could be measured in terms of temperature in Fahrenheit or Celsius,
|
131 |
+
and since temperature affects the demand for products such as clothing, food, and beverages. It is also one of the important factor
|
132 |
+
to be considered for causal analysis of Supply chain management.
|
133 |
+
Target Column/Prediction:
|
134 |
+
Backordered: A binary variable indicating whether the product was backordered (1) or not (0) during a specific
|
135 |
+
time period. This is the target variable that we want to predict""")
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
# # user_data = user_report()
|
141 |
+
# # st.subheader("Component Details")
|
142 |
+
# # st.write(user_data)
|
143 |
+
|
144 |
+
# # Function calling
|
145 |
+
# y_pred = prediction(user_data)
|
146 |
+
# st.write("Click here to see the Predictions")
|
147 |
+
# if st.button("Predict"):
|
148 |
+
# st.subheader(f"Next Failure is {y_pred} hours ")
|
149 |
+
|
150 |
+
# Product D, 9.0, 105.0, 219.0, 64.0, 2364.0, 71.24 - for this 0 (Backorders are unlikely to occur)
|
151 |
+
# #predict_backordered('Product C', 5.0, 105.0, 177.0, 38.0, 1598.0, 83.31) - for this 1 (Backorders are likely to occur)
|
152 |
|