Update app.py
Browse files
app.py
CHANGED
|
@@ -3,31 +3,60 @@ import pandas as pd
|
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
|
| 10 |
st.set_page_config(
|
| 11 |
-
page_title="Predictive Maintenance",
|
| 12 |
page_icon="π",
|
| 13 |
layout="centered"
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
st.title("π Predictive Maintenance System")
|
|
|
|
| 17 |
st.write(
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
)
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
#
|
| 26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
MODEL_REPO = "killswitch009/predictive-maintenance-model"
|
| 29 |
MODEL_FILE = "best_model.pkl"
|
| 30 |
|
|
|
|
| 31 |
@st.cache_resource
|
| 32 |
def load_model():
|
| 33 |
model_path = hf_hub_download(
|
|
@@ -36,21 +65,31 @@ def load_model():
|
|
| 36 |
)
|
| 37 |
return joblib.load(model_path)
|
| 38 |
|
| 39 |
-
#model = load_model()
|
| 40 |
|
| 41 |
try:
|
| 42 |
model = load_model()
|
| 43 |
st.success("β
Model loaded successfully!")
|
| 44 |
except Exception as e:
|
| 45 |
-
st.error(f"
|
| 46 |
st.stop()
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
#
|
| 50 |
-
#
|
| 51 |
|
| 52 |
st.header("Enter Engine Sensor Values")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
engine_rpm = st.number_input(
|
| 55 |
"Engine RPM",
|
| 56 |
min_value=0,
|
|
@@ -60,59 +99,87 @@ engine_rpm = st.number_input(
|
|
| 60 |
lub_pressure = st.number_input(
|
| 61 |
"Lub Oil Pressure",
|
| 62 |
min_value=0.0,
|
| 63 |
-
value=3.
|
| 64 |
)
|
| 65 |
|
| 66 |
fuel_pressure = st.number_input(
|
| 67 |
"Fuel Pressure",
|
| 68 |
min_value=0.0,
|
| 69 |
-
value=6.
|
| 70 |
)
|
| 71 |
|
| 72 |
coolant_pressure = st.number_input(
|
| 73 |
"Coolant Pressure",
|
| 74 |
min_value=0.0,
|
| 75 |
-
value=2.
|
| 76 |
)
|
| 77 |
|
| 78 |
lub_temp = st.number_input(
|
| 79 |
"Lub Oil Temperature",
|
| 80 |
min_value=0.0,
|
| 81 |
-
value=77.
|
| 82 |
)
|
| 83 |
|
| 84 |
coolant_temp = st.number_input(
|
| 85 |
"Coolant Temperature",
|
| 86 |
min_value=0.0,
|
| 87 |
-
value=78.
|
| 88 |
)
|
| 89 |
|
| 90 |
-
#
|
| 91 |
-
#
|
| 92 |
-
#
|
| 93 |
|
| 94 |
-
if st.button("Predict Engine Condition"):
|
| 95 |
|
| 96 |
input_data = pd.DataFrame({
|
| 97 |
-
"Engine rpm":[engine_rpm],
|
| 98 |
-
"Lub oil pressure":[lub_pressure],
|
| 99 |
-
"Fuel pressure":[fuel_pressure],
|
| 100 |
-
"Coolant pressure":[coolant_pressure],
|
| 101 |
-
"lub oil temp":[lub_temp],
|
| 102 |
-
"Coolant temp":[coolant_temp]
|
| 103 |
})
|
| 104 |
|
| 105 |
prediction = model.predict(input_data)[0]
|
| 106 |
probability = model.predict_proba(input_data)[0]
|
| 107 |
|
| 108 |
-
st.
|
|
|
|
|
|
|
| 109 |
|
| 110 |
if prediction == 1:
|
| 111 |
st.error("β οΈ Engine Requires Maintenance")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
else:
|
| 113 |
-
st.success("β
Engine Operating Normally")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
+
# ==========================================================
|
| 7 |
+
# PAGE CONFIGURATION
|
| 8 |
+
# ==========================================================
|
| 9 |
|
| 10 |
st.set_page_config(
|
| 11 |
+
page_title="Predictive Maintenance System",
|
| 12 |
page_icon="π",
|
| 13 |
layout="centered"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
# ==========================================================
|
| 17 |
+
# TITLE
|
| 18 |
+
# ==========================================================
|
| 19 |
+
|
| 20 |
st.title("π Predictive Maintenance System")
|
| 21 |
+
|
| 22 |
st.write(
|
| 23 |
"""
|
| 24 |
+
This application predicts whether an engine requires maintenance
|
| 25 |
+
based on its sensor readings using a trained **AdaBoost Classifier**.
|
| 26 |
+
"""
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# ==========================================================
|
| 30 |
+
# SIDEBAR
|
| 31 |
+
# ==========================================================
|
| 32 |
+
|
| 33 |
+
st.sidebar.title("π Project Information")
|
| 34 |
+
|
| 35 |
+
st.sidebar.markdown("""
|
| 36 |
+
### π€ Model
|
| 37 |
+
AdaBoost Classifier
|
| 38 |
+
|
| 39 |
+
### π― Model Accuracy
|
| 40 |
+
**66.75%**
|
| 41 |
+
|
| 42 |
+
### π Dataset
|
| 43 |
+
Predictive Maintenance Dataset
|
| 44 |
+
|
| 45 |
+
### π Deployment
|
| 46 |
+
Hugging Face Spaces
|
| 47 |
+
|
| 48 |
+
### π©βπ» Developed By
|
| 49 |
+
Barnali Nayak
|
| 50 |
+
""")
|
| 51 |
+
|
| 52 |
+
# ==========================================================
|
| 53 |
+
# LOAD MODEL
|
| 54 |
+
# ==========================================================
|
| 55 |
|
| 56 |
MODEL_REPO = "killswitch009/predictive-maintenance-model"
|
| 57 |
MODEL_FILE = "best_model.pkl"
|
| 58 |
|
| 59 |
+
|
| 60 |
@st.cache_resource
|
| 61 |
def load_model():
|
| 62 |
model_path = hf_hub_download(
|
|
|
|
| 65 |
)
|
| 66 |
return joblib.load(model_path)
|
| 67 |
|
|
|
|
| 68 |
|
| 69 |
try:
|
| 70 |
model = load_model()
|
| 71 |
st.success("β
Model loaded successfully!")
|
| 72 |
except Exception as e:
|
| 73 |
+
st.error(f"Unable to load model.\n\n{e}")
|
| 74 |
st.stop()
|
| 75 |
|
| 76 |
+
# ==========================================================
|
| 77 |
+
# USER INPUTS
|
| 78 |
+
# ==========================================================
|
| 79 |
|
| 80 |
st.header("Enter Engine Sensor Values")
|
| 81 |
|
| 82 |
+
st.info("""
|
| 83 |
+
### Example Sensor Values
|
| 84 |
+
|
| 85 |
+
- Engine RPM : **700**
|
| 86 |
+
- Lub Oil Pressure : **2.5**
|
| 87 |
+
- Fuel Pressure : **12**
|
| 88 |
+
- Coolant Pressure : **3.2**
|
| 89 |
+
- Lub Oil Temperature : **84**
|
| 90 |
+
- Coolant Temperature : **82**
|
| 91 |
+
""")
|
| 92 |
+
|
| 93 |
engine_rpm = st.number_input(
|
| 94 |
"Engine RPM",
|
| 95 |
min_value=0,
|
|
|
|
| 99 |
lub_pressure = st.number_input(
|
| 100 |
"Lub Oil Pressure",
|
| 101 |
min_value=0.0,
|
| 102 |
+
value=3.20
|
| 103 |
)
|
| 104 |
|
| 105 |
fuel_pressure = st.number_input(
|
| 106 |
"Fuel Pressure",
|
| 107 |
min_value=0.0,
|
| 108 |
+
value=6.50
|
| 109 |
)
|
| 110 |
|
| 111 |
coolant_pressure = st.number_input(
|
| 112 |
"Coolant Pressure",
|
| 113 |
min_value=0.0,
|
| 114 |
+
value=2.30
|
| 115 |
)
|
| 116 |
|
| 117 |
lub_temp = st.number_input(
|
| 118 |
"Lub Oil Temperature",
|
| 119 |
min_value=0.0,
|
| 120 |
+
value=77.00
|
| 121 |
)
|
| 122 |
|
| 123 |
coolant_temp = st.number_input(
|
| 124 |
"Coolant Temperature",
|
| 125 |
min_value=0.0,
|
| 126 |
+
value=78.00
|
| 127 |
)
|
| 128 |
|
| 129 |
+
# ==========================================================
|
| 130 |
+
# PREDICTION
|
| 131 |
+
# ==========================================================
|
| 132 |
|
| 133 |
+
if st.button("π Predict Engine Condition", use_container_width=True):
|
| 134 |
|
| 135 |
input_data = pd.DataFrame({
|
| 136 |
+
"Engine rpm": [engine_rpm],
|
| 137 |
+
"Lub oil pressure": [lub_pressure],
|
| 138 |
+
"Fuel pressure": [fuel_pressure],
|
| 139 |
+
"Coolant pressure": [coolant_pressure],
|
| 140 |
+
"lub oil temp": [lub_temp],
|
| 141 |
+
"Coolant temp": [coolant_temp]
|
| 142 |
})
|
| 143 |
|
| 144 |
prediction = model.predict(input_data)[0]
|
| 145 |
probability = model.predict_proba(input_data)[0]
|
| 146 |
|
| 147 |
+
st.divider()
|
| 148 |
+
|
| 149 |
+
st.header("Prediction Result")
|
| 150 |
|
| 151 |
if prediction == 1:
|
| 152 |
st.error("β οΈ Engine Requires Maintenance")
|
| 153 |
+
st.warning(
|
| 154 |
+
"The sensor readings indicate that the engine may require maintenance. "
|
| 155 |
+
"A detailed inspection is recommended."
|
| 156 |
+
)
|
| 157 |
else:
|
| 158 |
+
st.success("β
Engine is Operating Normally")
|
| 159 |
+
st.balloons()
|
| 160 |
+
|
| 161 |
+
st.divider()
|
| 162 |
+
|
| 163 |
+
st.header("Prediction Confidence")
|
| 164 |
+
|
| 165 |
+
st.metric(
|
| 166 |
+
"Healthy Engine Probability",
|
| 167 |
+
f"{probability[0]*100:.2f}%"
|
| 168 |
+
)
|
| 169 |
+
st.progress(float(probability[0]))
|
| 170 |
+
|
| 171 |
+
st.metric(
|
| 172 |
+
"Maintenance Required Probability",
|
| 173 |
+
f"{probability[1]*100:.2f}%"
|
| 174 |
+
)
|
| 175 |
+
st.progress(float(probability[1]))
|
| 176 |
+
|
| 177 |
+
# ==========================================================
|
| 178 |
+
# FOOTER
|
| 179 |
+
# ==========================================================
|
| 180 |
|
| 181 |
+
st.markdown("---")
|
| 182 |
|
| 183 |
+
st.caption(
|
| 184 |
+
"Developed by **Brijesh Pandey** | Python β’ Scikit-learn β’ Streamlit β’ Hugging Face"
|
| 185 |
+
)
|