Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ st.set_page_config(
|
|
| 15 |
|
| 16 |
|
| 17 |
# ==============================
|
| 18 |
-
# LOAD MODEL
|
| 19 |
# ==============================
|
| 20 |
|
| 21 |
@st.cache_resource
|
|
@@ -31,7 +31,11 @@ def load_model():
|
|
| 31 |
return None
|
| 32 |
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
# ==============================
|
|
@@ -65,27 +69,39 @@ coolant_temp = st.number_input("Coolant Temperature", 50.0, 150.0, 85.0)
|
|
| 65 |
|
| 66 |
if st.button("Predict Engine Condition"):
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# ==============================
|
| 18 |
+
# LOAD MODEL
|
| 19 |
# ==============================
|
| 20 |
|
| 21 |
@st.cache_resource
|
|
|
|
| 31 |
return None
|
| 32 |
|
| 33 |
|
| 34 |
+
with st.spinner("Loading model..."):
|
| 35 |
+
model = load_model()
|
| 36 |
+
|
| 37 |
+
if model is None:
|
| 38 |
+
st.stop()
|
| 39 |
|
| 40 |
|
| 41 |
# ==============================
|
|
|
|
| 69 |
|
| 70 |
if st.button("Predict Engine Condition"):
|
| 71 |
|
| 72 |
+
try:
|
| 73 |
+
# FIXED COLUMN ORDER
|
| 74 |
+
columns = [
|
| 75 |
+
"Engine rpm",
|
| 76 |
+
"Lub oil pressure",
|
| 77 |
+
"Fuel pressure",
|
| 78 |
+
"Coolant pressure",
|
| 79 |
+
"Lub oil temp",
|
| 80 |
+
"Coolant temp"
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
input_data = pd.DataFrame([[
|
| 84 |
+
engine_rpm,
|
| 85 |
+
lub_oil_pressure,
|
| 86 |
+
fuel_pressure,
|
| 87 |
+
coolant_pressure,
|
| 88 |
+
lub_oil_temp,
|
| 89 |
+
coolant_temp
|
| 90 |
+
]], columns=columns)
|
| 91 |
+
|
| 92 |
+
prediction = model.predict(input_data)[0]
|
| 93 |
+
|
| 94 |
+
st.subheader("Prediction Result")
|
| 95 |
+
|
| 96 |
+
# Optional probability
|
| 97 |
+
if hasattr(model, "predict_proba"):
|
| 98 |
+
prob = model.predict_proba(input_data)[0][1]
|
| 99 |
+
st.write(f"Failure Probability: {prob:.2f}")
|
| 100 |
+
|
| 101 |
+
if prediction == 1:
|
| 102 |
+
st.error("Engine Failure Likely – Maintenance Required")
|
| 103 |
+
else:
|
| 104 |
+
st.success("Engine Operating Normally")
|
| 105 |
+
|
| 106 |
+
except Exception as e:
|
| 107 |
+
st.error(f"Prediction failed: {e}")
|