Spaces:
Sleeping
Sleeping
File size: 2,986 Bytes
4efe81c 3540c4e 3472a33 4efe81c 3472a33 4efe81c 3472a33 4efe81c d01afd1 3472a33 d01afd1 4efe81c 3472a33 d01afd1 3472a33 2876d6d d01afd1 3540c4e d01afd1 3472a33 d01afd1 3540c4e 3472a33 4efe81c 3472a33 d01afd1 3472a33 d01afd1 3472a33 d01afd1 3472a33 d01afd1 | 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 87 88 89 90 91 | import streamlit as st
import pandas as pd
import joblib
import numpy as np
from huggingface_hub import hf_hub_download
# --- MODEL LOADING ---
REPO_ID = "P-Mishra/engine-predictive-maintenance"
MODEL_FILENAME = "rf_predictive_maintenance.pkl"
@st.cache_resource
def load_model():
try:
model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
return joblib.load(model_path)
except Exception as e:
st.error(f"Error loading model from Hub: {e}")
return None
model = load_model()
# --- UI SETUP ---
st.set_page_config(page_title="Engine Health Monitor", page_icon="🚢")
st.title("🚢 Engine Predictive Maintenance")
st.write("Professional Monitoring System for Engine Health")
# --- USER INPUTS ---
col1, col2 = st.columns(2)
with col1:
engine_rpm = st.number_input("Engine RPM", value=1200.0)
lub_oil_pressure = st.number_input("Lubricating Oil Pressure (bar)", value=4.5)
fuel_pressure = st.number_input("Fuel Pressure (bar)", value=5.0)
coolant_pressure = st.number_input("Coolant Pressure (bar)", value=2.5)
with col2:
lub_oil_temp = st.number_input("Lubricating Oil Temp (°C)", value=85.0)
coolant_temp = st.number_input("Coolant Temp (°C)", value=80.0)
# --- FEATURE ENGINEERING ---
eps = 1e-6
coolant_temp_pressure_interaction = coolant_temp * coolant_pressure
coolant_temp_pressure_ratio = coolant_temp / (coolant_pressure + eps)
lub_oil_temp_engine_rpm_interaction = lub_oil_temp * engine_rpm
fuel_pressure_engine_rpm_ratio = fuel_pressure / (engine_rpm + eps)
# --- DATAFRAME CONSTRUCTION (VERIFIED ORDER) ---
# This list matches your model's 'feature_names_in_' exactly.
feature_columns = [
'engine_rpm',
'lub_oil_pressure',
'fuel_pressure',
'coolant_pressure',
'lub_oil_temp',
'coolant_temp',
'coolant_temp_pressure_interaction',
'coolant_temp_pressure_ratio',
'lub_oil_temp_engine_rpm_interaction',
'fuel_pressure_engine_rpm_ratio'
]
input_data = pd.DataFrame([[
engine_rpm,
lub_oil_pressure,
fuel_pressure,
coolant_pressure,
lub_oil_temp,
coolant_temp,
coolant_temp_pressure_interaction,
coolant_temp_pressure_ratio,
lub_oil_temp_engine_rpm_interaction,
fuel_pressure_engine_rpm_ratio
]], columns=feature_columns)
# --- PREDICTION ---
if st.button("Analyze Engine Condition"):
if model is not None:
try:
prediction = model.predict(input_data)
st.divider()
if prediction[0] == 1:
st.error("### 🚨 Result: Maintenance Required")
st.write("High failure risk detected based on sensor interaction patterns.")
else:
st.success("### ✅ Result: Normal Operation")
st.write("Engine is operating within safe nominal parameters.")
except Exception as e:
st.error(f"Prediction Error: {e}")
else:
st.error("Model not loaded correctly.")
|