import streamlit as st import pandas as pd import joblib from huggingface_hub import hf_hub_download # ========================================================== # PAGE CONFIGURATION # ========================================================== st.set_page_config( page_title="Predictive Maintenance System", page_icon="🚗", layout="centered" ) # ========================================================== # TITLE # ========================================================== st.title("🚗 Predictive Maintenance System") st.write(""" This application predicts whether an engine requires maintenance based on its sensor readings using a trained **AdaBoost Classifier**. """) # ========================================================== # SIDEBAR # ========================================================== st.sidebar.title("📌 Project Information") st.sidebar.markdown(""" ### 🤖 Model AdaBoost Classifier ### 🎯 Model Accuracy **66.75%** ### 📊 Dataset Predictive Maintenance Dataset ### 🚀 Deployment Hugging Face Spaces ### 👩‍💻 Developed By Brijesh Pandey """) # ========================================================== # LOAD MODEL # ========================================================== MODEL_REPO = "killswitch009/predictive-maintenance-model" MODEL_FILE = "best_model.pkl" @st.cache_resource def load_model(): model_path = hf_hub_download( repo_id=MODEL_REPO, filename=MODEL_FILE ) return joblib.load(model_path) try: model = load_model() st.success("✅ Model loaded successfully!") except Exception as e: st.error(f"Unable to load model.\n\n{e}") st.stop() # ========================================================== # USER INPUTS # ========================================================== st.header("Enter Engine Sensor Values") with st.expander("📋 Example Sensor Values", expanded=True): st.markdown(""" - **Engine RPM:** 700 - **Lub Oil Pressure:** 2.5 - **Fuel Pressure:** 12 - **Coolant Pressure:** 3.2 - **Lub Oil Temperature:** 84 - **Coolant Temperature:** 82 """) engine_rpm = st.number_input( "Engine RPM", min_value=0, value=800 ) lub_pressure = st.number_input( "Lub Oil Pressure", min_value=0.0, value=3.20 ) fuel_pressure = st.number_input( "Fuel Pressure", min_value=0.0, value=6.50 ) coolant_pressure = st.number_input( "Coolant Pressure", min_value=0.0, value=2.30 ) lub_temp = st.number_input( "Lub Oil Temperature", min_value=0.0, value=77.00 ) coolant_temp = st.number_input( "Coolant Temperature", min_value=0.0, value=78.00 ) # ========================================================== # PREDICTION # ========================================================== if st.button("🔍 Predict Engine Condition", use_container_width=True): input_data = pd.DataFrame({ "Engine rpm": [engine_rpm], "Lub oil pressure": [lub_pressure], "Fuel pressure": [fuel_pressure], "Coolant pressure": [coolant_pressure], "lub oil temp": [lub_temp], "Coolant temp": [coolant_temp] }) prediction = model.predict(input_data)[0] probability = model.predict_proba(input_data)[0] healthy_prob = probability[0] * 100 maintenance_prob = probability[1] * 100 st.divider() st.header("Prediction Result") if prediction == 1: st.error("⚠️ Engine Requires Maintenance") st.warning( "The sensor readings indicate that the engine may require maintenance. " "A detailed inspection is recommended." ) else: st.success("✅ Engine is Operating Normally") st.divider() st.header("Prediction Confidence") col1, col2 = st.columns(2) with col1: st.metric( label="✅ Healthy Engine", value=f"{healthy_prob:.2f}%" ) with col2: st.metric( label="⚠️ Maintenance Required", value=f"{maintenance_prob:.2f}%" ) st.divider() st.subheader("Summary") if prediction == 1: st.markdown(f""" - **Prediction:** Engine Requires Maintenance - **Healthy Probability:** **{healthy_prob:.2f}%** - **Maintenance Probability:** **{maintenance_prob:.2f}%** - **Recommendation:** Schedule maintenance as soon as possible. """) else: st.markdown(f""" - **Prediction:** Engine Operating Normally - **Healthy Probability:** **{healthy_prob:.2f}%** - **Maintenance Probability:** **{maintenance_prob:.2f}%** - **Recommendation:** Continue normal operation and routine monitoring. """) # ========================================================== # FOOTER # ========================================================== st.markdown("---") st.caption( "Developed by Brijesh Pandey | Python • Scikit-learn • Streamlit • Hugging Face" )