Spaces:
Sleeping
Sleeping
File size: 2,783 Bytes
6562e37 75b28b3 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 13e9605 df12e54 13e9605 6562e37 13e9605 6562e37 13e9605 6562e37 | 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 | import streamlit as st
import numpy as np
import joblib
import pandas as pd
from huggingface_hub import hf_hub_download
# ----------------------------------------------------
# Load trained model
# ----------------------------------------------------
MODEL_PATH = hf_hub_download(
repo_id="raj2261992/predictive_maintenance_model",
filename="engine_condition_xgboost_v1.joblib"
)
model = joblib.load(MODEL_PATH)
# ----------------------------------------------------
# Page Config
# ----------------------------------------------------
st.set_page_config(
page_title="Engine Health Prediction",
layout="centered"
)
st.title("🛠️ Predictive Maintenance – Engine Health")
st.markdown("Enter live sensor values to predict engine condition.")
st.divider()
# ----------------------------------------------------
# Sidebar Inputs
# ----------------------------------------------------
st.sidebar.header("Sensor Inputs")
engine_rpm = st.sidebar.number_input("Engine RPM", min_value=0.0, value=1500.0)
lub_oil_pressure = st.sidebar.number_input(
"Lub Oil Pressure", min_value=0.0, value=3.5
)
fuel_pressure = st.sidebar.number_input(
"Fuel Pressure", min_value=0.0, value=4.0
)
coolant_pressure = st.sidebar.number_input(
"Coolant Pressure", min_value=0.0, value=2.0
)
lub_oil_temp = st.sidebar.number_input(
"Lub Oil Temperature", min_value=0.0, value=80.0
)
coolant_temp = st.sidebar.number_input(
"Coolant Temperature", min_value=0.0, value=75.0
)
# ----------------------------------------------------
# Prediction
# ----------------------------------------------------
if st.button("Predict Engine Condition"):
# IMPORTANT: Must be DataFrame (not NumPy)
input_data = pd.DataFrame([{
"Engine rpm": float(engine_rpm),
"Lub oil pressure": float(lub_oil_pressure),
"Fuel pressure": float(fuel_pressure),
"Coolant pressure": float(coolant_pressure),
"lub oil temp": float(lub_oil_temp),
"Coolant temp": float(coolant_temp),
}])
# Debug display (optional)
st.write("### Input Data")
st.write(input_data)
# Predict probability
prob = model.predict_proba(input_data)[0][1]
threshold = 0.45
prediction = int(prob >= threshold)
st.subheader("Prediction Result")
if prediction == 0:
st.success("Engine Condition: NORMAL")
else:
st.error("Engine Condition: FAULTY / AT RISK")
st.metric("Failure Probability", f"{prob:.2%}")
st.divider()
st.write("### Input Summary")
st.table(input_data)
# ----------------------------------------------------
# Footer
# ----------------------------------------------------
st.markdown("---")
st.caption("Predictive Maintenance Dashboard | Built with Streamlit")
|