Sriranjan commited on
Commit
00bb12c
·
1 Parent(s): 9c7b3b1

Final UX Polish: Integrated icons

Browse files
Files changed (1) hide show
  1. app.py +86 -115
app.py CHANGED
@@ -4,126 +4,97 @@ import joblib
4
  from huggingface_hub import hf_hub_download
5
  import os
6
 
7
- # --- PAGE CONFIGURATION ---
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
- This dashboard analyzes real-time engine sensor data to predict the **probability of failure**.
38
- By identifying potential faults before they occur, you can shift from reactive to proactive maintenance.
39
- """)
40
-
41
- st.markdown("---")
42
-
43
- if error:
44
- st.error(error)
45
- st.stop()
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
- features = pd.DataFrame(data, index=[0])
79
- return features
80
-
81
- input_df = user_input_features()
82
-
83
- # --- MAIN VIEW: Display Inputs & Results ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- col1, col2 = st.columns([2, 1])
 
 
86
 
 
 
87
  with col1:
88
- st.subheader("📊 Captured Sensor Data Summary")
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.subheader("🚀 AI Prediction Engine")
103
- predict_btn = st.button("Analyze Engine Health")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- if predict_btn:
106
- with st.spinner('Analyzing sensor patterns...'):
107
- try:
108
- # Run prediction
109
- prediction = pipeline.predict(input_df)
110
- prediction_proba = pipeline.predict_proba(input_df)
111
-
112
- confidence = prediction_proba[0][prediction[0]] * 100
113
-
114
- st.markdown("---")
115
-
116
- # UX Feature: Use Prominent Status boxes for the final verdict
117
- if prediction[0] == 0:
118
- st.success(f"### Engine Status: ACTIVE/HEALTHY")
119
- st.write(f"Confidence: **{confidence:.1f}%** (This reading shows a **low risk** of imminent failure.)")
120
- else:
121
- st.error(f"### Engine Status: FAULTY/RISK")
122
- st.write(f"Confidence: **{confidence:.1f}%** (This pattern indicates a **high probability** of failure. Maintenance is **required**.)")
123
-
124
- except Exception as e:
125
- st.error(f"Prediction error: {e}")
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")