-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathapp.py
More file actions
86 lines (74 loc) · 4.61 KB
/
app.py
File metadata and controls
86 lines (74 loc) · 4.61 KB
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
import streamlit as st
import pickle
import numpy as np
# Load the trained model (replace 'model.pkl' with your actual file name)
with open('model.pkl', 'rb') as file:
model = pickle.load(file)
# Define the customized ranges for each feature based on dataset statistics
custom_ranges = {
'Engine rpm': (61.0, 2239.0),
'Lub oil pressure': (0.003384, 7.265566),
'Fuel pressure': (0.003187, 21.138326),
'Coolant pressure': (0.002483, 7.478505),
'lub oil temp': (71.321974, 89.580796),
'Coolant temp': (61.673325, 195.527912),
'Temperature_difference': (-22.669427, 119.008526)
}
# Feature Descriptions
feature_descriptions = {
'Engine rpm': 'Revolution per minute of the engine.',
'Lub oil pressure': 'Pressure of the lubricating oil.',
'Fuel pressure': 'Pressure of the fuel.',
'Coolant pressure': 'Pressure of the coolant.',
'lub oil temp': 'Temperature of the lubricating oil.',
'Coolant temp': 'Temperature of the coolant.',
'Temperature_difference': 'Temperature difference between components.'
}
# Engine Condition Prediction App
def main():
st.title("Engine Condition Prediction")
# Display feature descriptions
st.sidebar.title("Feature Descriptions")
for feature, description in feature_descriptions.items():
st.sidebar.markdown(f"**{feature}:** {description}")
# Input widgets with customized ranges
engine_rpm = st.slider("Engine RPM", min_value=float(custom_ranges['Engine rpm'][0]),
max_value=float(custom_ranges['Engine rpm'][1]),
value=float(custom_ranges['Engine rpm'][1] / 2))
lub_oil_pressure = st.slider("Lub Oil Pressure", min_value=custom_ranges['Lub oil pressure'][0],
max_value=custom_ranges['Lub oil pressure'][1],
value=(custom_ranges['Lub oil pressure'][0] + custom_ranges['Lub oil pressure'][1]) / 2)
fuel_pressure = st.slider("Fuel Pressure", min_value=custom_ranges['Fuel pressure'][0],
max_value=custom_ranges['Fuel pressure'][1],
value=(custom_ranges['Fuel pressure'][0] + custom_ranges['Fuel pressure'][1]) / 2)
coolant_pressure = st.slider("Coolant Pressure", min_value=custom_ranges['Coolant pressure'][0],
max_value=custom_ranges['Coolant pressure'][1],
value=(custom_ranges['Coolant pressure'][0] + custom_ranges['Coolant pressure'][1]) / 2)
lub_oil_temp = st.slider("Lub Oil Temperature", min_value=custom_ranges['lub oil temp'][0],
max_value=custom_ranges['lub oil temp'][1],
value=(custom_ranges['lub oil temp'][0] + custom_ranges['lub oil temp'][1]) / 2)
coolant_temp = st.slider("Coolant Temperature", min_value=custom_ranges['Coolant temp'][0],
max_value=custom_ranges['Coolant temp'][1],
value=(custom_ranges['Coolant temp'][0] + custom_ranges['Coolant temp'][1]) / 2)
temp_difference = st.slider("Temperature Difference", min_value=custom_ranges['Temperature_difference'][0],
max_value=custom_ranges['Temperature_difference'][1],
value=(custom_ranges['Temperature_difference'][0] + custom_ranges['Temperature_difference'][1]) / 2)
# Predict button
if st.button("Predict Engine Condition"):
result, confidence = predict_condition(engine_rpm, lub_oil_pressure, fuel_pressure, coolant_pressure, lub_oil_temp, coolant_temp, temp_difference)
# Explanation
if result == 0:
st.info(f"The engine is predicted to be in a normal condition. As the Confidence level of the machine is : {1.0 - confidence:.2%}")
else:
st.warning(f"Warning! Please investigate further,As the Confidence level of the machine is : {1.0 - confidence:.2%}")
# Reset button
if st.button("Reset Values"):
st.experimental_rerun()
# Function to predict engine condition
def predict_condition(engine_rpm, lub_oil_pressure, fuel_pressure, coolant_pressure, lub_oil_temp, coolant_temp, temp_difference):
input_data = np.array([engine_rpm, lub_oil_pressure, fuel_pressure, coolant_pressure, lub_oil_temp, coolant_temp, temp_difference]).reshape(1, -1)
prediction = model.predict(input_data)
confidence = model.predict_proba(input_data)[:, 1] # For binary classification, adjust as needed
return prediction[0], confidence[0]
if __name__ == "__main__":
main()