Priyanka-Kumavat-At-TE's picture
Update app.py
56880ce
# 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)