ThirdEyeData/Component_Repair_Time_Prediction
1
1import tensorflow as tf2from tensorflow import keras3import numpy as np4import matplotlib.pyplot as plt5import pandas as pd6from sklearn.model_selection import train_test_split7from sklearn import preprocessing8import seaborn as sns9from sklearn.preprocessing import LabelEncoder10import pickle11import streamlit as st 12 13st.title('Repair Time Prediction')14#DLoading the ataset15#df = pd.read_csv('repair_time_sample_50k_modified2.csv')16 17#new_data = df18#df.drop(['SRU serial number','Date of Manufacture', 'Snag Description'], axis = 1, inplace=True)19 20 21# DATA from user22def user_report():23 Aircraft_Type = st.sidebar.selectbox('Aircraft Type',("AH-64","UH-60","UH-63","UH-62","UH-61","AH-65"))24 if Aircraft_Type=="AH-64":25 Aircraft_Type=026 elif Aircraft_Type=="UH-60":27 Aircraft_Type=228 elif Aircraft_Type=="UH-63":29 Aircraft_Type=530 elif Aircraft_Type=="UH-62":31 Aircraft_Type=432 elif Aircraft_Type=="UH-61":33 Aircraft_Type=334 else:35 Aircraft_Type=136 manufacturer = st.sidebar.selectbox("Manufacturer",37 ("JKL Company", "GHI Company","AGS Company","ABC Company","XYZ Company" ))38 if manufacturer=='JKL Company':39 manufacturer=340 elif manufacturer=="GHI Company":41 manufacturer=242 elif manufacturer=="AGS Company":43 manufacturer=144 elif manufacturer=="ABC Company":45 manufacturer =046 else:47 manufacturer=448 component_age = st.sidebar.slider('Component Age (in hours)', 500,2000, 600 )49 Issue_category= st.sidebar.selectbox("Issue Category",50 ("Display", "Unservicable","Bootup Problem","Engine Failure","Electrical Fault" ))51 if Issue_category=='Display':52 Issue_category=153 elif Issue_category=="Unservicable":54 Issue_category=455 elif Issue_category=="Bootup Problem":56 Issue_category=057 elif Issue_category=="Engine Failure":58 Issue_category=359 else:60 Issue_category=261 Snag_Severity = st.sidebar.selectbox("Snag Severity",62 ("Low", "Medium","High" ))63 if Snag_Severity =='Low':64 Snag_Severity=165 elif Snag_Severity=="Medium":66 Snag_Severity =267 else:68 Snag_Severity=069 Customer= st.sidebar.selectbox("Customer",70 ("IAF", "ARMY","NAVY" ))71 if Customer =='IAF':72 Customer=173 elif Customer=="ARMY":74 Customer =075 else:76 Customer=277 Technician_Skill_level= st.sidebar.selectbox("Technician Skill level",78 ("Expert", "Intermediate","Novice" ))79 if Technician_Skill_level =='Expert':80 Technician_Skill_level=081 elif Technician_Skill_level=="Intermediate":82 Technician_Skill_level =183 else:84 Technician_Skill_level=285 prior_maintainence = st.sidebar.selectbox('Prior Maintainence',("Regular","Irregular"))86 if prior_maintainence =='Regular':87 prior_maintainence=188 else:89 prior_maintainence=090 Logistics_Time = st.sidebar.slider('Logistics Time (hr)', 2,21, 5 )91 total_operating_hours = st.sidebar.slider('Total Operating Hours)', 50,2000, 500 )92 operating_temperature = st.sidebar.slider('Operating Temperature', 10,25, 15 )93 previous_number_of_repairs = st.sidebar.number_input('Enter the Previous Number of Repairs Undergone 0 to 3 )',min_value=0,max_value=3,step=1)94 Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',100,133,115) 95 96 97 user_report_data = {98 'Aircraft Type':Aircraft_Type,99 'Manufacturer':manufacturer,100 'Component_Age':component_age,101 'Issue_category':Issue_category,102 'Snag Severity': Snag_Severity,103 'Customer':Customer,104 'Technician Skill level':Technician_Skill_level,105 'Prior Maintenance': prior_maintainence,106 'Logistics Time (hr)':Logistics_Time,107 'total_operating_hours':total_operating_hours,108 'operating_temperature':operating_temperature,109 'previous_number_of_repairs':previous_number_of_repairs,110 'Power_Input_Voltage':Power_Input_Voltage111 112 }113 report_data = pd.DataFrame(user_report_data, index=[0])114 return report_data 115 116#Customer Data117user_data = user_report()118st.header("Component Details")119st.write(user_data)120 121def preprocess_dataset(X): 122 x = X.values #returns a numpy array123 min_max_scaler = preprocessing.MinMaxScaler()124 x_scaled = min_max_scaler.fit_transform(x)125 X_df = pd.DataFrame(x_scaled)126 return X_df127 128def label_encoding(data):129 le = LabelEncoder()130 cat = data.select_dtypes(include='O').keys()131 categ = list(cat)132 data[categ] = data[categ].apply(le.fit_transform)133 # X = data.loc[:,data.columns!= "Time required for repair (in hours)"]134 # y = data['Time required for repair (in hours)']135 # return X,y136 return data137 138def prediction(df):139 #X = df.loc[:,df.columns!= "Time required for repair (in hours)"]140 #y = df['Time required for repair (in hours)']141 #X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)142 #print(X_train.shape)143 #print(X_test.shape)144 #X_test_encoded = label_encoding(df)145 #X_test_df = preprocess_dataset(df)146 x_model = pickle.load(open('repair_time_model.pkl','rb'))147 pred = x_model.predict(df)148 #X_test['Actual_time_to_repair'] = y_test149 #X_test['Predicted_time_to_repair'] = pred150 #X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/repair_time_prediction_results.csv')151 #print(X_test.head())152 return pred153 154y_pred = prediction(user_data)155 156if st.button("Predict"):157 st.subheader(f"Time required to Repair the Component is {y_pred[0]} hours")