killswitch009's picture
Update app.py
c1412d9 verified
Raw
History Blame Contribute Delete
4.89 kB
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"
)