File size: 3,717 Bytes
39c3820 2794848 39c3820 2794848 39c3820 2794848 39c3820 2794848 39c3820 2794848 39c3820 2794848 39c3820 |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
# ---------------------------------------------------
# Page config
# ---------------------------------------------------
st.set_page_config(
page_title="Predictive Maintenance Engine Risk Predictor",
layout="centered"
)
# ---------------------------------------------------
# Load Model from Hugging Face
# ---------------------------------------------------
REPO_ID = "subratm62/predictive-maintenance"
MODEL_FILE = "predictive_maintenance_pipeline.joblib"
@st.cache_resource
def load_model():
model_path = hf_hub_download(
repo_id=REPO_ID,
filename=MODEL_FILE
)
return joblib.load(model_path)
model = load_model()
# Classification threshold
classification_threshold = 0.50
# ---------------------------------------------------
# UI Header
# ---------------------------------------------------
st.title("π§ Predictive Maintenance β Engine Failure Risk")
st.write(
"""
Enter live engine sensor readings to estimate **failure risk**.
This tool supports proactive maintenance decisions.
"""
)
st.markdown("---")
# ---------------------------------------------------
# Sensor Inputs
# ---------------------------------------------------
st.subheader("Engine Sensor Inputs")
col1, col2 = st.columns(2)
with col1:
engine_rpm = st.number_input(
"Engine RPM",
min_value=0.0,
max_value=5000.0,
value=750.0
)
lub_oil_pressure = st.number_input(
"Lub Oil Pressure",
min_value=0.0,
max_value=10.0,
value=3.0
)
fuel_pressure = st.number_input(
"Fuel Pressure",
min_value=0.0,
max_value=50.0,
value=6.0
)
with col2:
coolant_pressure = st.number_input(
"Coolant Pressure",
min_value=0.0,
max_value=10.0,
value=2.0
)
lub_oil_temp = st.number_input(
"Lub Oil Temperature",
min_value=50.0,
max_value=150.0,
value=77.0
)
coolant_temp = st.number_input(
"Coolant Temperature",
min_value=50.0,
max_value=250.0,
value=78.0
)
st.markdown("---")
# ---------------------------------------------------
# Prepare input dataframe
# ---------------------------------------------------
input_data = pd.DataFrame([{
"Engine rpm": engine_rpm,
"Lub oil pressure": lub_oil_pressure,
"Fuel pressure": fuel_pressure,
"Coolant pressure": coolant_pressure,
"lub oil temp": lub_oil_temp,
"Coolant temp": coolant_temp
}])
# ---------------------------------------------------
# Prediction
# ---------------------------------------------------
if st.button("π Predict Failure Risk"):
probability = model.predict_proba(input_data)[0, 1]
prediction = int(probability >= classification_threshold)
st.subheader("Prediction Result")
if prediction == 1:
st.error(
"β FAILURE RISK β Maintenance inspection recommended."
)
else:
st.success(
"β
Engine operating within normal range."
)
st.write(f"**Failure Probability:** {probability:.4f}")
st.write(f"**Decision Threshold:** {classification_threshold:.2f}")
# Business interpretation
if probability > 0.75:
st.warning("Critical condition β immediate inspection advised.")
elif probability > 0.50:
st.info("Moderate risk β schedule maintenance soon.")
else:
st.write("Low operational risk detected.")
st.markdown("---")
st.caption(
"Model hosted on Hugging Face | Experiment tracking via MLflow | Built with Streamlit"
)
|