File size: 5,459 Bytes
34ffff8
 
 
 
 
 
 
 
 
 
 
57b4570
db00fdf
 
 
8bedea7
db00fdf
 
 
1a99552
 
 
2144e21
1a99552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4a094
1a99552
d04e3f5
1a99552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b08fc08
82fbc4d
b08fc08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82fbc4d
4fa075e
 
 
 
1a99552
db00fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b63347
 
 
 
 
 
db00fdf
b2bcf83
 
 
 
86018aa
 
 
 
 
 
 
db00fdf
3b63347
 
 
6919a3b
2258a85
6919a3b
3b63347
 
db00fdf
3b63347
0e6207c
 
 
 
 
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
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
import streamlit as st 

st.title("Rouge Component Prediction")
#Reading Dataset
df = pd.read_csv('identify_rogue_50K_ALL.csv')
print("Dataset Size:",df.shape)
st.sidebar.header('Enter the Components Details here')
# Dropping the SRU serial number
df.drop(['SRU serial number','Date of Manufacture','Last Maintenance Date','date of last failure'], axis = 1, inplace=True)

# DATA from user
def user_report():
  manufacturer = st.sidebar.selectbox("Manufacturer",
        ("JKL Company", "GHI Company","AGS Company","ABC Company","XYZ Company" ))
  if manufacturer=='JKL Company':
      manufacturer=3
  elif manufacturer=="GHI Company":
      manufacturer=2
  elif manufacturer=="AGS Company":
      manufacturer=1
  elif manufacturer=="ABC Company":
      manufacturer =0
  else:
      manufacturer=4
  component_age = st.sidebar.slider('Component Age (in hours)', 500,2000, 600 )
  total_operating_hours = st.sidebar.slider('Total Operating Hours)', 50,2000, 500 )
  usage_intensity = st.sidebar.slider('Usage Intensity hours/day', 0,9, 5 )
  last_maintance_type = st.sidebar.selectbox('Last Mantainence Type', ("Preventive","Corrective") )
  if last_maintance_type=="Preventive":
      last_maintance_type=1
  else:
      last_maintance_type=0
  previous_number_of_repairs = st.sidebar.number_input('Enter the Previous Number of Repairs Undergone  0 to 5 )',min_value=0,max_value=5,step=1)
  operating_temperature = st.sidebar.slider('Operating Temperature', 10,25, 15 )
  humidity = st.sidebar.slider('Humidity', 20,105, 25 )
  Vibration_Level = st.sidebar.slider('Vibration Level', 2,7, 2 )
  Pressure = st.sidebar.slider('Pressure', 200,550, 250 )
  Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',100,133,115)
  repair_type = st.sidebar.selectbox('Repair Type', ("Hardware","Software") )
  if repair_type=='Hardware':
      repair_type=0
  else:
      repair_type=1
  number_of_inspection = st.sidebar.selectbox('Number of Inspections',('1','2'))
  if number_of_inspection=='1':
      number_of_inspection=1
  else:
      number_of_inspection=2
  number_of_inspection_6months = st.sidebar.selectbox('Number of Inspections in last 6 Months',('0','1'))
  if number_of_inspection_6months=='0':
      number_of_inspection_6months=0
  else:
      number_of_inspection_6months=1
  prior_maintainence = st.sidebar.selectbox('Prior Maintainence',("Regular","Irregular"))
  if prior_maintainence =='Regular':
      prior_maintainence=1
  else:
      prior_maintainence=0

  user_report_data = {
      'Manufacturer':manufacturer,
      'Component_Age':component_age,
      'Total Operating Hours':total_operating_hours,
      'Usage Intensity (hours/day)':usage_intensity,
      'Last Maintenance Type': last_maintance_type,
      'Previous number of repairs':previous_number_of_repairs,
      'Operating Temperature':operating_temperature,
      'Humidity': humidity,
      'Vibration Level':Vibration_Level,
      'Pressure':Pressure,
      'Power Input Voltage (V)':Power_Input_Voltage,
      'repair type':repair_type ,
      'total number of inspection':number_of_inspection,
      'No. of Inspections in Last 6 Months':number_of_inspection_6months,
      'Prior Maintenance':prior_maintainence
           
  }
  report_data = pd.DataFrame(user_report_data, index=[0])
  return report_data    
    
#Customer Data
user_data = user_report()
st.header("Component Details")
st.write(user_data)

def label_encoder(df):
  le = LabelEncoder()
  cat = df.select_dtypes(include='O').keys()
  categ = list(cat)
  df[categ] = df[categ].apply(le.fit_transform)
  return df

def preprocess_dataset(X):  
  x = X.values #returns a numpy array
  min_max_scaler = preprocessing.MinMaxScaler()
  x_scaled = min_max_scaler.fit_transform(x)
  X_df = pd.DataFrame(x_scaled)
  return X_df

def prediction(df):
  #X = df.loc[:,df.columns!= "Rogue LRU/SRU (Target)"]
  #y = df["Rogue LRU/SRU (Target)"]
  #X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)
  #print(X_train.shape)
  #print(X_test.shape)
  X_test_encoded = label_encoder(df)
  X_test_df = preprocess_dataset(X_test_encoded)
  #x_model = loaded_model = tf.keras.models.load_model('my_model')
    #x_model = tf.keras.models.load_model('my_model.h5')
  try:
        x_model = tf.keras.models.load_model('my_model.h5')
  except (OSError, ValueError):
        # Load the model as a TFSMLayer if .h5 loading fails
        tfs_layer = tf.keras.layers.TFSMLayer('my_model', call_endpoint='serving_default')
        # Create a new model using the TFSMLayer
        inputs = tf.keras.Input(shape=(X_test_df.shape[1],))
        outputs = tfs_layer(inputs)
        x_model = tf.keras.Model(inputs=inputs, outputs=outputs)
  y_pred = x_model.predict(X_test_df)
  #predicition = []
  #for i in list(y_pred):
  if y_pred ==0:
      return 'Component is Good'
  else:
      return 'Component is not Good'
  #X_test['Actual_time_to_repair'] = y_test
  #X_test['Predicted_time_to_repair'] = predicition
  # X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/rogue_test_data.csv')
  #print(X_test.head())

y_pred = prediction(user_data)

if st.button("Predict"):
    st.subheader(y_pred)