saritha5 commited on
Commit
95b9724
·
1 Parent(s): 3588a42

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +157 -0
app.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from tensorflow import keras
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import pandas as pd
6
+ from sklearn.model_selection import train_test_split
7
+ from sklearn import preprocessing
8
+ import seaborn as sns
9
+ from sklearn.preprocessing import LabelEncoder
10
+ import pickle
11
+ import streamlit as st
12
+
13
+ st.title('Repair Time Prediction')
14
+ #DLoading the ataset
15
+ #df = pd.read_csv('repair_time_sample_50k_modified2.csv')
16
+
17
+ new_data = df
18
+ #df.drop(['SRU serial number','Date of Manufacture', 'Snag Description'], axis = 1, inplace=True)
19
+
20
+
21
+ # DATA from user
22
+ def 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=0
26
+ elif Aircraft_Type=="UH-60":
27
+ Aircraft_Type=2
28
+ elif Aircraft_Type=="UH-63":
29
+ Aircraft_Type=5
30
+ elif Aircraft_Type=="UH-62":
31
+ Aircraft_Type=4
32
+ elif Aircraft_Type=="UH-61":
33
+ Aircraft_Type=3
34
+ else:
35
+ Aircraft_Type=1
36
+ manufacturer = st.sidebar.selectbox("Manufacturer",
37
+ ("JKL Company", "GHI Company","AGS Company","ABC Company","ABC Company","XYZ Company" ))
38
+ if manufacturer=='JKL Company':
39
+ manufacturer=3
40
+ elif manufacturer=="GHI Company":
41
+ manufacturer=2
42
+ elif manufacturer=="AGS Company":
43
+ manufacturer=1
44
+ elif manufacturer=="ABC Company":
45
+ manufacturer =0
46
+ else:
47
+ manufacturer=4
48
+ 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=1
53
+ elif Issue_category=="Unservicable":
54
+ Issue_category=4
55
+ elif Issue_category=="Bootup Problem":
56
+ Issue_category=0
57
+ elif Issue_category=="Engine Failure":
58
+ Issue_category=3
59
+ else:
60
+ Issue_category=2
61
+ Snag Severity = st.sidebar.selectbox("Snag Severity",
62
+ ("Low", "Medium","High" ))
63
+ if Snag Severity =='Low':
64
+ Snag Severity=1
65
+ elif Snag Severity=="Medium":
66
+ Snag Severity =2
67
+ else:
68
+ Snag Severity=0
69
+ Customer= st.sidebar.selectbox("Customer",
70
+ ("IAF", "ARMY","NAVY" ))
71
+ if Customer =='IAF':
72
+ Customer=1
73
+ elif Customer=="ARMY":
74
+ Customer =0
75
+ else:
76
+ Customer=2
77
+ Technician_Skill_level= st.sidebar.selectbox("Technician Skill level",
78
+ ("Expert", "Intermediate","Novice" ))
79
+ if Technician_Skill_level =='Expert':
80
+ Technician_Skill_level=0
81
+ elif Technician_Skill_level=="Intermediate":
82
+ Technician_Skill_level =1
83
+ else:
84
+ Technician_Skill_level=2
85
+ prior_maintainence = st.sidebar.selectbox('Prior Maintainence',("Regular","Irregular"))
86
+ if prior_maintainence =='Regular':
87
+ prior_maintainence=1
88
+ else:
89
+ prior_maintainence=0
90
+ 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_hour,
108
+ 'operating_temperature':operating_temperature,
109
+ 'previous_number_of_repairs':previous_number_of_repairs, ,
110
+ 'Power_Input_Voltage':Power_Input_Voltage
111
+
112
+ }
113
+ report_data = pd.DataFrame(user_report_data, index=[0])
114
+ return report_data
115
+
116
+ #Customer Data
117
+ user_data = user_report()
118
+ st.header("Component Details")
119
+ st.write(user_data)
120
+
121
+ def preprocess_dataset(X):
122
+ x = X.values #returns a numpy array
123
+ min_max_scaler = preprocessing.MinMaxScaler()
124
+ x_scaled = min_max_scaler.fit_transform(x)
125
+ X_df = pd.DataFrame(x_scaled)
126
+ return X_df
127
+
128
+ def 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,y
136
+ return data
137
+
138
+ def 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(X_test_encoded)
146
+ x_model = pickle.load(open('repair_time_model.pkl','rb'))
147
+ pred = x_model.predict(X_test_df)
148
+ #X_test['Actual_time_to_repair'] = y_test
149
+ #X_test['Predicted_time_to_repair'] = pred
150
+ #X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/repair_time_prediction_results.csv')
151
+ #print(X_test.head())
152
+ return pred
153
+
154
+ y_pred = prediction(user_data)
155
+
156
+ if st.button("Predict"):
157
+ st.subheader(f"Time required to Repairs the Component is {y_pred} in hours")