Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import numpy as np
|
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
# --- MODEL LOADING ---
|
| 8 |
-
# Fetches the model directly from your Hugging Face model repository
|
| 9 |
REPO_ID = "P-Mishra/engine-predictive-maintenance"
|
| 10 |
MODEL_FILENAME = "rf_predictive_maintenance.pkl"
|
| 11 |
|
|
@@ -23,55 +22,69 @@ model = load_model()
|
|
| 23 |
# --- UI SETUP ---
|
| 24 |
st.set_page_config(page_title="Engine Health Monitor", page_icon="🚢")
|
| 25 |
st.title("🚢 Engine Predictive Maintenance")
|
| 26 |
-
st.write("
|
| 27 |
|
| 28 |
# --- USER INPUTS ---
|
| 29 |
col1, col2 = st.columns(2)
|
| 30 |
|
| 31 |
with col1:
|
| 32 |
engine_rpm = st.number_input("Engine RPM", value=1200.0)
|
| 33 |
-
lub_oil_temp = st.number_input("Lubricating Oil Temp (°C)", value=85.0)
|
| 34 |
lub_oil_pressure = st.number_input("Lubricating Oil Pressure (bar)", value=4.5)
|
|
|
|
|
|
|
| 35 |
|
| 36 |
with col2:
|
| 37 |
-
|
| 38 |
coolant_temp = st.number_input("Coolant Temp (°C)", value=80.0)
|
| 39 |
-
coolant_pressure = st.number_input("Coolant Pressure (bar)", value=2.5)
|
| 40 |
|
| 41 |
-
# --- FEATURE ENGINEERING
|
| 42 |
eps = 1e-6
|
| 43 |
coolant_temp_pressure_interaction = coolant_temp * coolant_pressure
|
| 44 |
coolant_temp_pressure_ratio = coolant_temp / (coolant_pressure + eps)
|
| 45 |
lub_oil_temp_engine_rpm_interaction = lub_oil_temp * engine_rpm
|
| 46 |
fuel_pressure_engine_rpm_ratio = fuel_pressure / (engine_rpm + eps)
|
| 47 |
|
| 48 |
-
# --- DATAFRAME CONSTRUCTION ---
|
| 49 |
-
#
|
| 50 |
feature_columns = [
|
| 51 |
-
'engine_rpm',
|
| 52 |
-
'
|
| 53 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
'fuel_pressure_engine_rpm_ratio'
|
| 55 |
]
|
| 56 |
|
| 57 |
input_data = pd.DataFrame([[
|
| 58 |
-
engine_rpm,
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
fuel_pressure_engine_rpm_ratio
|
| 62 |
]], columns=feature_columns)
|
| 63 |
|
| 64 |
# --- PREDICTION ---
|
| 65 |
-
if st.button("
|
| 66 |
if model is not None:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
else:
|
| 77 |
-
st.error("Model not
|
|
|
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
# --- MODEL LOADING ---
|
|
|
|
| 8 |
REPO_ID = "P-Mishra/engine-predictive-maintenance"
|
| 9 |
MODEL_FILENAME = "rf_predictive_maintenance.pkl"
|
| 10 |
|
|
|
|
| 22 |
# --- UI SETUP ---
|
| 23 |
st.set_page_config(page_title="Engine Health Monitor", page_icon="🚢")
|
| 24 |
st.title("🚢 Engine Predictive Maintenance")
|
| 25 |
+
st.write("Professional Monitoring System for Engine Health")
|
| 26 |
|
| 27 |
# --- USER INPUTS ---
|
| 28 |
col1, col2 = st.columns(2)
|
| 29 |
|
| 30 |
with col1:
|
| 31 |
engine_rpm = st.number_input("Engine RPM", value=1200.0)
|
|
|
|
| 32 |
lub_oil_pressure = st.number_input("Lubricating Oil Pressure (bar)", value=4.5)
|
| 33 |
+
fuel_pressure = st.number_input("Fuel Pressure (bar)", value=5.0)
|
| 34 |
+
coolant_pressure = st.number_input("Coolant Pressure (bar)", value=2.5)
|
| 35 |
|
| 36 |
with col2:
|
| 37 |
+
lub_oil_temp = st.number_input("Lubricating Oil Temp (°C)", value=85.0)
|
| 38 |
coolant_temp = st.number_input("Coolant Temp (°C)", value=80.0)
|
|
|
|
| 39 |
|
| 40 |
+
# --- FEATURE ENGINEERING ---
|
| 41 |
eps = 1e-6
|
| 42 |
coolant_temp_pressure_interaction = coolant_temp * coolant_pressure
|
| 43 |
coolant_temp_pressure_ratio = coolant_temp / (coolant_pressure + eps)
|
| 44 |
lub_oil_temp_engine_rpm_interaction = lub_oil_temp * engine_rpm
|
| 45 |
fuel_pressure_engine_rpm_ratio = fuel_pressure / (engine_rpm + eps)
|
| 46 |
|
| 47 |
+
# --- DATAFRAME CONSTRUCTION (VERIFIED ORDER) ---
|
| 48 |
+
# This list matches your model's 'feature_names_in_' exactly.
|
| 49 |
feature_columns = [
|
| 50 |
+
'engine_rpm',
|
| 51 |
+
'lub_oil_pressure',
|
| 52 |
+
'fuel_pressure',
|
| 53 |
+
'coolant_pressure',
|
| 54 |
+
'lub_oil_temp',
|
| 55 |
+
'coolant_temp',
|
| 56 |
+
'coolant_temp_pressure_interaction',
|
| 57 |
+
'coolant_temp_pressure_ratio',
|
| 58 |
+
'lub_oil_temp_engine_rpm_interaction',
|
| 59 |
'fuel_pressure_engine_rpm_ratio'
|
| 60 |
]
|
| 61 |
|
| 62 |
input_data = pd.DataFrame([[
|
| 63 |
+
engine_rpm,
|
| 64 |
+
lub_oil_pressure,
|
| 65 |
+
fuel_pressure,
|
| 66 |
+
coolant_pressure,
|
| 67 |
+
lub_oil_temp,
|
| 68 |
+
coolant_temp,
|
| 69 |
+
coolant_temp_pressure_interaction,
|
| 70 |
+
coolant_temp_pressure_ratio,
|
| 71 |
+
lub_oil_temp_engine_rpm_interaction,
|
| 72 |
fuel_pressure_engine_rpm_ratio
|
| 73 |
]], columns=feature_columns)
|
| 74 |
|
| 75 |
# --- PREDICTION ---
|
| 76 |
+
if st.button("Analyze Engine Condition"):
|
| 77 |
if model is not None:
|
| 78 |
+
try:
|
| 79 |
+
prediction = model.predict(input_data)
|
| 80 |
+
st.divider()
|
| 81 |
+
if prediction[0] == 1:
|
| 82 |
+
st.error("### 🚨 Result: Maintenance Required")
|
| 83 |
+
st.write("High failure risk detected based on sensor interaction patterns.")
|
| 84 |
+
else:
|
| 85 |
+
st.success("### ✅ Result: Normal Operation")
|
| 86 |
+
st.write("Engine is operating within safe nominal parameters.")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
st.error(f"Prediction Error: {e}")
|
| 89 |
else:
|
| 90 |
+
st.error("Model not loaded correctly.")
|