saritha5's picture
Update app.py
0b130b2
raw
history blame
5.39 kB
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 pickle
import streamlit as st
st.title('Repair Time Prediction')
#DLoading the ataset
#df = pd.read_csv('repair_time_sample_50k_modified2.csv')
#new_data = df
#df.drop(['SRU serial number','Date of Manufacture', 'Snag Description'], axis = 1, inplace=True)
# DATA from user
def user_report():
Aircraft_Type = st.sidebar.selectbox('Aircraft Type',("AH-64","UH-60","UH-63","UH-62","UH-61","AH-65"))
if Aircraft_Type=="AH-64":
Aircraft_Type=0
elif Aircraft_Type=="UH-60":
Aircraft_Type=2
elif Aircraft_Type=="UH-63":
Aircraft_Type=5
elif Aircraft_Type=="UH-62":
Aircraft_Type=4
elif Aircraft_Type=="UH-61":
Aircraft_Type=3
else:
Aircraft_Type=1
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 )
Issue_category= st.sidebar.selectbox("Issue Category",
("Display", "Unservicable","Bootup Problem","Engine Failure","Electrical Fault" ))
if Issue_category=='Display':
Issue_category=1
elif Issue_category=="Unservicable":
Issue_category=4
elif Issue_category=="Bootup Problem":
Issue_category=0
elif Issue_category=="Engine Failure":
Issue_category=3
else:
Issue_category=2
Snag_Severity = st.sidebar.selectbox("Snag Severity",
("Low", "Medium","High" ))
if Snag_Severity =='Low':
Snag_Severity=1
elif Snag_Severity=="Medium":
Snag_Severity =2
else:
Snag_Severity=0
Customer= st.sidebar.selectbox("Customer",
("IAF", "ARMY","NAVY" ))
if Customer =='IAF':
Customer=1
elif Customer=="ARMY":
Customer =0
else:
Customer=2
Technician_Skill_level= st.sidebar.selectbox("Technician Skill level",
("Expert", "Intermediate","Novice" ))
if Technician_Skill_level =='Expert':
Technician_Skill_level=0
elif Technician_Skill_level=="Intermediate":
Technician_Skill_level =1
else:
Technician_Skill_level=2
prior_maintainence = st.sidebar.selectbox('Prior Maintainence',("Regular","Irregular"))
if prior_maintainence =='Regular':
prior_maintainence=1
else:
prior_maintainence=0
Logistics_Time = st.sidebar.slider('Logistics Time (hr)', 2,21, 5 )
total_operating_hours = st.sidebar.slider('Total Operating Hours)', 50,2000, 500 )
operating_temperature = st.sidebar.slider('Operating Temperature', 10,25, 15 )
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)
Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',100,133,115)
user_report_data = {
'Aircraft Type':Aircraft_Type,
'Manufacturer':manufacturer,
'Component_Age':component_age,
'Issue_category':Issue_category,
'Snag Severity': Snag_Severity,
'Customer':Customer,
'Technician Skill level':Technician_Skill_level,
'Prior Maintenance': prior_maintainence,
'Logistics Time (hr)':Logistics_Time,
'total_operating_hours':total_operating_hours,
'operating_temperature':operating_temperature,
'previous_number_of_repairs':previous_number_of_repairs,
'Power_Input_Voltage':Power_Input_Voltage
}
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 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 label_encoding(data):
le = LabelEncoder()
cat = data.select_dtypes(include='O').keys()
categ = list(cat)
data[categ] = data[categ].apply(le.fit_transform)
# X = data.loc[:,data.columns!= "Time required for repair (in hours)"]
# y = data['Time required for repair (in hours)']
# return X,y
return data
def prediction(df):
#X = df.loc[:,df.columns!= "Time required for repair (in hours)"]
#y = df['Time required for repair (in hours)']
#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_encoding(df)
#X_test_df = preprocess_dataset(df)
x_model = pickle.load(open('repair_time_model.pkl','rb'))
pred = x_model.predict(df)
#X_test['Actual_time_to_repair'] = y_test
#X_test['Predicted_time_to_repair'] = pred
#X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/repair_time_prediction_results.csv')
#print(X_test.head())
return pred
y_pred = prediction(user_data)
if st.button("Predict"):
st.subheader(f"Time required to Repair the Component is {y_pred[0]} hours")