File size: 7,393 Bytes
e59e6e4
 
 
 
 
 
 
 
46acc58
e59e6e4
 
 
 
 
d59bc9a
e59e6e4
 
349b16b
 
46acc58
349b16b
 
 
 
3d06d5d
 
 
 
 
 
 
 
 
 
 
d59bc9a
 
349b16b
c2d4beb
349b16b
 
 
 
 
 
 
 
312261f
d59bc9a
3d06d5d
d59bc9a
 
 
 
 
 
3d06d5d
 
 
 
 
 
 
56880ce
d59bc9a
3d06d5d
d59bc9a
 
 
 
 
3d06d5d
d59bc9a
 
 
 
 
3d06d5d
d59bc9a
 
 
 
 
3d06d5d
d59bc9a
 
 
 
 
3d06d5d
d59bc9a
 
 
 
 
3d06d5d
d59bc9a
 
 
3d06d5d
 
 
 
 
 
 
 
 
d59bc9a
 
3d06d5d
 
 
 
 
 
 
 
 
 
 
 
 
d59bc9a
3d06d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59bc9a
 
 
 
 
 
 
 
 
 
 
 
 
3d06d5d
d59bc9a
3d06d5d
 
 
d59bc9a
 
 
 
f9426a4
 
d59bc9a
f9426a4
d59bc9a
f9426a4
d59bc9a
 
f9426a4
d59bc9a
f9426a4
d59bc9a
f9426a4
d59bc9a
f9426a4
d59bc9a
f9426a4
d59bc9a
f9426a4
d59bc9a
436504d
d59bc9a
436504d
d59bc9a
 
 
 
 
 
 
3d06d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59bc9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# User Test Function (Prediction Script)

# Import required libraries
import pandas as pd
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import matplotlib.pyplot as plt
import seaborn as sns
import pickle

import warnings
warnings.filterwarnings("ignore", category=UserWarning)

import streamlit as st
import os

st.title('Supply Chain Causal Analysis')

st.write("""Supply Chain Causal Analysis Model: 
            This TensorFlow-powered model utilizes advanced machine learning techniques to analyze and predict causal relationships 
            among key factors in a supply chain, including product demand, lead time, in stock count, pricing, advertising, weather, 
            and backorder status.            
            By uncovering these causal relationships, the model enables businesses to optimize their supply chain operations, reduce costs,
            and improve customer satisfaction. 
            Developed using TensorFlow, a powerful deep learning framework, this model offers accurate and efficient insights 
            into the complex dynamics of supply chain operations, empowering businesses to make data-driven decisions and drive 
            operational excellence""")

st.sidebar.header('Supply Chain Features')

# loading the save model
model = tf.keras.models.load_model(os.path.join('Weights_Updated','Best_model.tf'), compile=False) 

# loading the product label encoding object
with open ('le_product.pkl','rb') as file:
  le_product = pickle.load(file)

# loading the scaling object
with open ('scaler_scca.pkl','rb') as file1:
  scaler = pickle.load(file1)


def user_report():
    
    # # For Product
    
    st.sidebar.write("**1: Product Name**")
    st.sidebar.write("Name of the Product")
    Product = st.sidebar.selectbox("",("Product A", "Product B","Product C","Product D"))
    if Product=='Product A':
        Product=0
    elif Product=="Product B":
        Product=1
    elif Product=="Product C": 
        Product=2
    else:
        Product=3
        
    # For Lead_time
    st.sidebar.write("**2: Lead_time**")
    st.sidebar.write("The average number of days taken to deliver the product after placing the order.")
    Lead_time = st.sidebar.slider('', 1,25,9)

    
    # For Demand
    st.sidebar.write("**3: Demand**")
    st.sidebar.write("The number of units of the product demanded during a specific time period.")
    Demand = st.sidebar.slider('', 20,182,105)

    
    # For In_stock
    st.sidebar.write("**4: In_stock**")
    st.sidebar.write("The number of units of the product currently available in the inventory.")
    In_stock = st.sidebar.slider('', 20,250,219)

    
    # For Price
    st.sidebar.write("**5: Price**")
    st.sidebar.write("The selling price of the product.")
    Price = st.sidebar.slider('', 10,100,64)

    
    # For Advertising
    st.sidebar.write("**6: Advertising**")
    st.sidebar.write("The amount spent on advertising the product during a specific time period.")
    Advertising = st.sidebar.slider('', 1000,4500,2364)

    
    # For Weather
    st.sidebar.write("**7: Weather**")
    st.sidebar.write("Weather condition during a specific time period that could affect the demand for the product.")
    Weather = st.sidebar.slider('', 30,110,71)

    # Create a DataFrame for the input data
    user_report_data = {'Product': [Product],
                        'Lead_time': [Lead_time],
                        'Demand': [Demand],
                        'In_stock': [In_stock],
                        'Price': [Price],
                        'Advertising': [Advertising],
                        'Weather': [Weather]}
    


    # # encoded the Product using loaded product label encoder object
    # le_product_encoded = le_product.transform([Product])[0]
    
    # # scaling the input_data using loaded scaler object
    # report_data = scaler.transform(input_data)

    report_data = pd.DataFrame(user_report_data, index=[0])
    return report_data 

    
# Supply Chain Data Details
user_data = user_report()
st.subheader("Selected Values of Supply Chain Features")
st.write(user_data)

# User_function 
def predict_backordered(user_data):

    df = pd.read_csv('Supply_chain_causal_analysis_Synthetic_Dataset_Final.csv')

    # # encoded the Product using loaded product label encoder object
    # Product = le_product.transform([Product])[0]

    # scaling the input_data using loaded scaler object
    user_data = scaler.transform(user_data)
    
    # Make predictions using the pre-trained TensorFlow model
    predictions = model.predict(user_data)
    if predictions == 1:
      return "Backorders are likely to occur."
    else:
      return "Backorders are unlikely to occur."

        
# CSS code for changing color of the button
st.markdown("""
    <style>
    .stButton button {
        background-color: #668f45;                        
        color: white;
    }
    </style>
    """, unsafe_allow_html=True)


# predictions
y_pred = predict_backordered(user_data)
if st.button("Predict Probability of the Product being Backordered"):
    st.subheader(y_pred)


# Display the title
st.title("Deployment in Real-World Scenarios")
# Display the title image
st.image("pasteImg.png", use_column_width=True)


# background-color: lightgreen;   (in CSS)

# st.write("""Features Used:

# The following are the input Varibles from the End user which needs to be enter, and then the application will predict whether 
# the particular Product has the chances of having Backorder or not.

# 1: Product: Name of the product.

# 2: Lead_time: The average number of days taken to deliver the product after placing the order.

# 3: Demand: The number of units of the product demanded during a specific time period.

# 4: In_stock: The number of units of the product currently available in the inventory.

# 5: Price: The selling price of the product.

# 6: Advertising: The amount spent on advertising the product during a specific time period.

# 7: Weather: Weather condition during a specific time period that could affect the demand for the product.

# In a retail scenario, weather could be measured in terms of temperature in Fahrenheit or Celsius,
# and since temperature affects the demand for products such as clothing, food, and beverages. It is also one of the important factor
# to be considered for causal analysis of Supply chain management.

# Target Column/Prediction: 
# Backordered: A binary variable indicating whether the product will be backordered (1) or not (0) during a specific 
#              time period. This is the target variable that we want to predict""")




# # user_data = user_report()
# # st.subheader("Component Details")
# # st.write(user_data)

# # Function calling
# y_pred = prediction(user_data)
# st.write("Click here to see the Predictions")
# if st.button("Predict"):
#     st.subheader(f"Next Failure is {y_pred} hours ")

# Product D, 9.0, 105.0, 219.0, 64.0, 2364.0, 71.24 - for this 0 (Backorders are unlikely to occur)
# #predict_backordered('Product C', 5.0, 105.0, 177.0, 38.0, 1598.0, 83.31) - for this 1 (Backorders are likely to occur)