Kabil007 commited on
Commit
8051e30
·
verified ·
1 Parent(s): 0da2c3f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import streamlit as stream
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ #importing the model
7
+ with open("svm_model.pkl", 'rb') as model_file:
8
+ model = pickle.load(model_file)
9
+
10
+ #importing the scaler model
11
+ with open("scaler.pkl", 'rb') as scaler_file:
12
+ scaler = pickle.load(scaler_file)
13
+
14
+ log_df = pd.DataFrame(columns=['Engine rpm', 'Lub oil pressure', 'Fuel pressure', 'Coolant pressure', 'lub oil temp', 'Coolant temp', 'Prediction'])
15
+
16
+ def EngineHealth_predict(input_data, model, scaler, log_df):
17
+
18
+ columns = ['Engine rpm', 'Lub oil pressure', 'Fuel pressure', 'Coolant pressure', 'lub oil temp', 'Coolant temp']
19
+ input_df = pd.DataFrame([input_data], columns=columns)
20
+
21
+ input_array = np.array(input_df).reshape(1, -1)
22
+
23
+ input_scaled = scaler.transform(input_array)
24
+
25
+ prediction = model.predict(input_scaled)
26
+
27
+
28
+ if prediction[0] == 0:
29
+ health_status = "Engine is in Good Health!"
30
+ else:
31
+ health_status = "Engine is not in Good Health"
32
+
33
+ input_data.append(prediction[0])
34
+ log_df.loc[len(log_df)] = input_data
35
+
36
+ return health_status, log_df
37
+
38
+ stream.title("Engine Health Prediction")
39
+
40
+ engine_rpm = stream.number_input("Enter Engine rpm:", min_value=0.0, step=0.1)
41
+ lub_oil_pressure = stream.number_input("Enter Lub oil pressure:", min_value=0.0, step=0.1)
42
+ fuel_pressure = stream.number_input("Enter Fuel pressure:", min_value=0.0, step=0.1)
43
+ coolant_pressure = stream.number_input("Enter Coolant pressure:", min_value=0.0, step=0.1)
44
+ lub_oil_temp = stream.number_input("Enter Lub oil temp:", min_value=0.0, step=0.1)
45
+ coolant_temp = stream.number_input("Enter Coolant temp:", min_value=0.0, step=0.1)
46
+
47
+
48
+ if stream.button('Predict'):
49
+ input_data = [
50
+ engine_rpm,
51
+ lub_oil_pressure,
52
+ fuel_pressure,
53
+ coolant_pressure,
54
+ lub_oil_temp,
55
+ coolant_temp
56
+ ]
57
+
58
+ health_status, log_df = EngineHealth_predict(input_data, model, scaler, log_df)
59
+
60
+ stream.write(f"Prediction: {health_status}")
61
+
62
+ # Display the log DataFrame
63
+ stream.write("Log of Predictions:")
64
+ stream.dataframe(log_df)