Debashre2824 commited on
Commit
d4d9252
·
verified ·
1 Parent(s): 0191ac9

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +145 -0
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ # Set page configuration
7
+ st.set_page_config(
8
+ page_title="Engine Predictive Maintenance",
9
+ page_icon="⚙️",
10
+ layout="wide"
11
+ )
12
+
13
+ # Load the trained model
14
+ @st.cache_resource
15
+ def load_model():
16
+ model = joblib.load('best_xgboost_model.pkl')
17
+ return model
18
+
19
+ model = load_model()
20
+
21
+ # Title and description
22
+ st.title("⚙️ Engine Predictive Maintenance System")
23
+ st.markdown("""
24
+ This application predicts whether an engine is **Normal** or **Faulty** based on sensor readings.
25
+ Enter the sensor values below to get a prediction.
26
+ """)
27
+
28
+ # Create two columns for better layout
29
+ col1, col2 = st.columns(2)
30
+
31
+ with col1:
32
+ st.subheader("📊 Input Sensor Readings")
33
+
34
+ # Input fields for the 6 features
35
+ engine_rpm = st.number_input(
36
+ "Engine RPM",
37
+ min_value=0.0,
38
+ max_value=10000.0,
39
+ value=2000.0,
40
+ step=100.0,
41
+ help="Engine Revolutions Per Minute"
42
+ )
43
+
44
+ lub_oil_pressure = st.number_input(
45
+ "Lub Oil Pressure (psi)",
46
+ min_value=0.0,
47
+ max_value=200.0,
48
+ value=50.0,
49
+ step=1.0,
50
+ help="Lubricating Oil Pressure"
51
+ )
52
+
53
+ fuel_pressure = st.number_input(
54
+ "Fuel Pressure (psi)",
55
+ min_value=0.0,
56
+ max_value=200.0,
57
+ value=50.0,
58
+ step=1.0,
59
+ help="Fuel Pressure"
60
+ )
61
+
62
+ with col2:
63
+ st.subheader("🌡️ Temperature & Pressure")
64
+
65
+ coolant_pressure = st.number_input(
66
+ "Coolant Pressure (psi)",
67
+ min_value=0.0,
68
+ max_value=200.0,
69
+ value=50.0,
70
+ step=1.0,
71
+ help="Coolant Pressure"
72
+ )
73
+
74
+ lub_oil_temp = st.number_input(
75
+ "Lub Oil Temperature (°C)",
76
+ min_value=0.0,
77
+ max_value=200.0,
78
+ value=80.0,
79
+ step=1.0,
80
+ help="Lubricating Oil Temperature"
81
+ )
82
+
83
+ coolant_temp = st.number_input(
84
+ "Coolant Temperature (°C)",
85
+ min_value=0.0,
86
+ max_value=150.0,
87
+ value=70.0,
88
+ step=1.0,
89
+ help="Coolant Temperature"
90
+ )
91
+
92
+ # Predict button
93
+ if st.button("🔍 Predict Engine Condition", type="primary"):
94
+ # Create input array with the correct feature order
95
+ input_data = np.array([[
96
+ engine_rpm,
97
+ lub_oil_pressure,
98
+ fuel_pressure,
99
+ coolant_pressure,
100
+ lub_oil_temp,
101
+ coolant_temp
102
+ ]])
103
+
104
+ # Make prediction
105
+ prediction = model.predict(input_data)[0]
106
+ prediction_proba = model.predict_proba(input_data)[0]
107
+
108
+ # Display results
109
+ st.markdown("---")
110
+ st.subheader("Prediction Result")
111
+
112
+ if prediction == 0:
113
+ st.success("**Engine Status: NORMAL**")
114
+ st.metric("Confidence", f"{prediction_proba[0]*100:.2f}%")
115
+ st.info("The engine is operating within normal parameters. Continue regular maintenance schedule.")
116
+ else:
117
+ st.error("**Engine Status: FAULTY**")
118
+ st.metric("Confidence", f"{prediction_proba[1]*100:.2f}%")
119
+ st.warning("The engine shows signs of potential failure. Immediate inspection recommended!")
120
+
121
+ # Show probability distribution
122
+ st.markdown("### Prediction Probabilities")
123
+ prob_df = pd.DataFrame({
124
+ 'Condition': ['Normal', 'Faulty'],
125
+ 'Probability': [prediction_proba[0], prediction_proba[1]]
126
+ })
127
+ st.bar_chart(prob_df.set_index('Condition'))
128
+
129
+ # Add footer with information
130
+ st.markdown("---")
131
+ st.markdown("""
132
+ **Model Information:**
133
+ - Algorithm: XGBoost Classifier
134
+ - F1-Score: 0.7630
135
+ - Recall: 87.01%
136
+ - Training Dataset: 19,535 engine records
137
+
138
+ **Features Used:**
139
+ 1. Engine RPM
140
+ 2. Lubricating Oil Pressure
141
+ 3. Fuel Pressure
142
+ 4. Coolant Pressure
143
+ 5. Lubricating Oil Temperature
144
+ 6. Coolant Temperature
145
+ """)