Final UX Polish: Integrated icons
Browse files
app.py
CHANGED
|
@@ -4,126 +4,97 @@ import joblib
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# --- PAGE
|
| 8 |
-
st.set_page_config(
|
| 9 |
-
page_title="Vehicle Predictive Maintenance AI",
|
| 10 |
-
page_icon="🔧",
|
| 11 |
-
layout="wide",
|
| 12 |
-
initial_sidebar_state="expanded"
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
# --- LOAD ASSETS (Image & Model) ---
|
| 16 |
-
def load_assets():
|
| 17 |
-
"""Download and load the model pipeline from Hugging Face."""
|
| 18 |
-
try:
|
| 19 |
-
# Download the unified pipeline
|
| 20 |
-
repo_id = "Sriranjan/Predictive_Maintenance_Model"
|
| 21 |
-
model_path = hf_hub_download(repo_id=repo_id, filename="engine_pipeline.joblib")
|
| 22 |
-
|
| 23 |
-
# 2. Load the pipeline
|
| 24 |
-
pipeline = joblib.load(model_path)
|
| 25 |
-
return pipeline, None
|
| 26 |
-
except Exception as e:
|
| 27 |
-
return None, f"Failed to load assets: {e}"
|
| 28 |
-
|
| 29 |
-
pipeline, error = load_assets()
|
| 30 |
-
|
| 31 |
-
# --- HEADER SECTION ---
|
| 32 |
-
st.title("🚗 AI-Powered Vehicle Predictive Maintenance Dashboard")
|
| 33 |
-
|
| 34 |
-
st.markdown("---")
|
| 35 |
|
|
|
|
| 36 |
st.markdown("""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
""
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# --- SIDEBAR INPUTS (Keep Main View Clean) ---
|
| 48 |
-
st.sidebar.header("🔧 Enter Real-Time Sensor Readings")
|
| 49 |
-
st.sidebar.markdown("Use the sliders below to provide current operational data.")
|
| 50 |
-
|
| 51 |
-
def user_input_features():
|
| 52 |
-
"""Capture sensor inputs via the sidebar."""
|
| 53 |
-
|
| 54 |
-
# Pressure Sensors Group
|
| 55 |
-
st.sidebar.subheader("Pressure (PSI)")
|
| 56 |
-
fuel_p = st.sidebar.slider("Fuel Pressure", 0.0, 100.0, 41.0, step=0.1, help="Expected range: 30-50 PSI")
|
| 57 |
-
lub_p = st.sidebar.slider("Lub Oil Pressure", 0.0, 100.0, 4.3, step=0.1, help="Expected range: 3-6 PSI")
|
| 58 |
-
coolant_p = st.sidebar.slider("Coolant Pressure", 0.0, 100.0, 1.8, step=0.1, help="Expected range: 1-3 PSI")
|
| 59 |
-
|
| 60 |
-
# Temperature Sensors Group
|
| 61 |
-
st.sidebar.subheader("Temperature (°F)")
|
| 62 |
-
lub_t = st.sidebar.slider("Lub Oil Temp", 0.0, 200.0, 81.0, step=1.0, help="Expected range: 75-90 °F")
|
| 63 |
-
coolant_t = st.sidebar.slider("Coolant Temp", 0.0, 200.0, 83.0, step=1.0, help="Expected range: 75-90 °F")
|
| 64 |
-
|
| 65 |
-
# Operational Group
|
| 66 |
-
st.sidebar.subheader("Operational")
|
| 67 |
-
rpm = st.sidebar.slider("Engine RPM", 0, 3000, 1200, step=10, help="Normal idle: 800-1500 RPM")
|
| 68 |
-
|
| 69 |
-
# Save inputs into a Dataframe
|
| 70 |
-
data = {
|
| 71 |
-
'Engine rpm': rpm,
|
| 72 |
-
'Lub oil pressure': lub_p,
|
| 73 |
-
'Fuel pressure': fuel_p,
|
| 74 |
-
'Coolant pressure': coolant_p,
|
| 75 |
-
'lub oil temp': lub_t,
|
| 76 |
-
'Coolant temp': coolant_t
|
| 77 |
}
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
|
|
|
|
|
|
| 87 |
with col1:
|
| 88 |
-
st.
|
| 89 |
-
|
| 90 |
-
# UX Feature: Use Metrics containers for better visual representation
|
| 91 |
-
m_col1, m_col2, m_col3 = st.columns(3)
|
| 92 |
-
|
| 93 |
-
m_col1.metric("Engine RPM", int(input_df['Engine rpm'][0]), "RPM", help="Rotations per Minute")
|
| 94 |
-
m_col2.metric("Lub Oil Pressure", f"{input_df['Lub oil pressure'][0]:.1f}", "PSI")
|
| 95 |
-
m_col3.metric("Fuel Pressure", f"{input_df['Fuel pressure'][0]:.1f}", "PSI")
|
| 96 |
-
|
| 97 |
-
m_col4, m_col5 = st.columns(2)
|
| 98 |
-
m_col4.metric("Lub Oil Temp", f"{input_df['lub oil temp'][0]:.0f}°F", help="Normal range: 75-90°F")
|
| 99 |
-
m_col5.metric("Coolant Temp", f"{input_df['Coolant temp'][0]:.0f}°F", help="Normal range: 75-90°F")
|
| 100 |
-
|
| 101 |
with col2:
|
| 102 |
-
st.
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
# --- FOOTER ---
|
| 128 |
-
st.markdown("---")
|
| 129 |
-
st.caption("Vehicle Predictive Maintenance Project - By Sriranjan Uppoor")
|
|
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# --- PAGE CONFIG ---
|
| 8 |
+
st.set_page_config(page_title="AI Engine Diagnostic", page_icon="🏎️", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# --- CUSTOM THEME CSS ---
|
| 11 |
st.markdown("""
|
| 12 |
+
<style>
|
| 13 |
+
.main { background-color: #f5f7f9; }
|
| 14 |
+
[data-testid="stMetricValue"] { font-size: 28px; color: #1f77b4; }
|
| 15 |
+
.stButton>button { width: 100%; border-radius: 5px; height: 3em; background-color: #1f77b4; color: white; }
|
| 16 |
+
.prediction-card {
|
| 17 |
+
padding: 20px;
|
| 18 |
+
border-radius: 10px;
|
| 19 |
+
background-color: white;
|
| 20 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 21 |
+
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
</style>
|
| 24 |
+
""", unsafe_allow_html=True)
|
| 25 |
+
|
| 26 |
+
@st.cache_resource
|
| 27 |
+
def load_model():
|
| 28 |
+
repo_id = "Sriranjan/Predictive_Maintenance_Model"
|
| 29 |
+
path = hf_hub_download(repo_id=repo_id, filename="engine_pipeline.joblib")
|
| 30 |
+
return joblib.load(path)
|
| 31 |
+
|
| 32 |
+
model = load_model()
|
| 33 |
+
|
| 34 |
+
# --- SIDEBAR: INPUT CONTROLS ---
|
| 35 |
+
with st.sidebar:
|
| 36 |
+
st.image("https://img.icons8.com/fluency/96/car-service.png", width=80)
|
| 37 |
+
st.header("Diagnostic Inputs")
|
| 38 |
+
st.info("Adjust sliders to simulate live engine telemetry.")
|
| 39 |
+
|
| 40 |
+
with st.expander("🌡️ Temperature Settings", expanded=True):
|
| 41 |
+
lub_t = st.slider("Lub Oil Temp (°C)", 60, 100, 77)
|
| 42 |
+
cool_t = st.slider("Coolant Temp (°C)", 60, 100, 78)
|
| 43 |
+
|
| 44 |
+
with st.expander("🧪 Pressure Settings", expanded=True):
|
| 45 |
+
fuel_p = st.slider("Fuel Pressure (bar)", 0.0, 20.0, 6.6)
|
| 46 |
+
lub_p = st.slider("Lub Oil Pressure (bar)", 0.0, 10.0, 3.3)
|
| 47 |
+
cool_p = st.slider("Coolant Pressure (bar)", 0.0, 10.0, 2.3)
|
| 48 |
+
|
| 49 |
+
with st.expander("⚙️ Engine Speed", expanded=True):
|
| 50 |
+
rpm = st.number_input("RPM", 0, 3000, 800)
|
| 51 |
|
| 52 |
+
# --- MAIN CONTENT ---
|
| 53 |
+
st.title("🏎️ Engine Health Diagnostic System")
|
| 54 |
+
st.markdown("Automated Failure Prediction using High-Fidelity Sensor Data")
|
| 55 |
|
| 56 |
+
# Create a 3-column top row for key metrics
|
| 57 |
+
col1, col2, col3 = st.columns(3)
|
| 58 |
with col1:
|
| 59 |
+
st.metric("Lubrication System", f"{lub_p} bar", f"{lub_t}°C")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
with col2:
|
| 61 |
+
st.metric("Fuel System", f"{fuel_p} bar", "Stable")
|
| 62 |
+
with col3:
|
| 63 |
+
st.metric("Cooling System", f"{cool_p} bar", f"{cool_t}°C")
|
| 64 |
+
|
| 65 |
+
st.divider()
|
| 66 |
+
|
| 67 |
+
# Lower Section: Analysis and Visualization
|
| 68 |
+
left_col, right_col = st.columns([1.5, 1])
|
| 69 |
+
|
| 70 |
+
with left_col:
|
| 71 |
+
st.subheader("📡 Live Telemetry Stream")
|
| 72 |
+
input_df = pd.DataFrame({
|
| 73 |
+
'Engine rpm': [rpm], 'Lub oil pressure': [lub_p],
|
| 74 |
+
'Fuel pressure': [fuel_p], 'Coolant pressure': [cool_p],
|
| 75 |
+
'lub oil temp': [lub_t], 'Coolant temp': [cool_t]
|
| 76 |
+
})
|
| 77 |
+
st.table(input_df)
|
| 78 |
|
| 79 |
+
# Simple Visual feedback
|
| 80 |
+
st.write("Temperature Saturation")
|
| 81 |
+
st.progress(max(0, min((cool_t - 60) / 40, 1.0)))
|
| 82 |
+
|
| 83 |
+
with right_col:
|
| 84 |
+
st.subheader("🧠 AI Verdict")
|
| 85 |
+
if st.button("RUN SYSTEM CHECK"):
|
| 86 |
+
pred = model.predict(input_df)[0]
|
| 87 |
+
prob = model.predict_proba(input_df)[0][pred] * 100
|
| 88 |
+
|
| 89 |
+
st.markdown('<div class="prediction-card">', unsafe_allow_html=True)
|
| 90 |
+
if pred == 0:
|
| 91 |
+
st.balloons()
|
| 92 |
+
st.markdown(f"<h1 style='color:green;'>✅ HEALTHY</h1>", unsafe_allow_html=True)
|
| 93 |
+
st.write(f"System Confidence: **{prob:.1f}%**")
|
| 94 |
+
else:
|
| 95 |
+
st.markdown(f"<h1 style='color:red;'>⚠️ FAULT RISK</h1>", unsafe_allow_html=True)
|
| 96 |
+
st.write(f"System Confidence: **{prob:.1f}%**")
|
| 97 |
+
st.warning("Immediate inspection required: Abnormal thermal/pressure signature detected.")
|
| 98 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 99 |
+
|
| 100 |
+
st.caption("© 2026 MLOps Framework | Developed by Sriranjan Uppoor")
|
|
|
|
|
|
|
|
|