# 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 Data') # 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) # DATA from user def user_report(): # For Product Product = st.sidebar.selectbox("Product Name",("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 Lead_time = st.sidebar.slider('Lead_time', 1,25,9) # For Demand Demand = st.sidebar.slider('Demand', 20,182,105) # For In_stock In_stock = st.sidebar.slider('In_stock', 20,250,219) # For Price Price = st.sidebar.slider('Price', 10,100,64) # For Advertising Advertising = st.sidebar.slider('Advertising', 1000,4500,2364) # For Weather Weather = st.sidebar.slider('Weather', 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("Supply Chain Data Details") 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(""" """, unsafe_allow_html=True) # Orange color code: #e88307 # Function calling y_pred = predict_backordered(user_data) if st.button("Predict"): st.subheader(y_pred) 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)