| import streamlit as st |
| import pandas as pd |
| import joblib |
| from huggingface_hub import hf_hub_download |
|
|
| |
| |
| |
|
|
| st.set_page_config( |
| page_title="Predictive Maintenance System", |
| page_icon="π", |
| layout="centered" |
| ) |
|
|
| |
| |
| |
|
|
| 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**. |
| """) |
|
|
| |
| |
| |
|
|
| 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 |
| """) |
|
|
| |
| |
| |
|
|
| 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() |
|
|
| |
| |
| |
|
|
| 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 |
| ) |
|
|
| |
| |
| |
|
|
| 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. |
| """) |
|
|
| |
| |
| |
|
|
| st.markdown("---") |
|
|
| st.caption( |
| "Developed by Brijesh Pandey | Python β’ Scikit-learn β’ Streamlit β’ Hugging Face" |
| ) |