Spaces:
Sleeping
Sleeping
| 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") | |