| import streamlit as st |
| import numpy as np |
| import pandas as pd |
| import requests |
| |
| |
| |
| st.set_page_config( |
| page_title="Engine Predictive Maintenance", |
| layout="wide" |
| ) |
|
|
| |
| |
| |
| st.markdown(""" |
| <style> |
| .block-container { |
| padding-top: 1rem; |
| padding-bottom: 1rem; |
| padding-left: 2rem; |
| padding-right: 2rem; |
| } |
| div[data-testid="stVerticalBlock"] { |
| gap: 0.6rem; |
| } |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| |
| |
| st.markdown(""" |
| <h2 style="margin-top: 0.5rem;"> |
| 🔧 Engine Predictive Maintenance System |
| </h2> |
| """, unsafe_allow_html=True) |
|
|
| st.markdown( |
| "Predict potential engine failures using real-time sensor inputs. " |
| "The model is optimized for **high fault recall** to minimize missed failures." |
| ) |
|
|
| |
| |
| |
| st.sidebar.header("⚙️ Prediction Settings") |
|
|
| threshold = st.sidebar.slider( |
| "Fault Detection Threshold", |
| min_value=0.1, |
| max_value=0.9, |
| value=0.5, |
| step=0.05, |
| help="Lower values increase fault detection (recall), higher values reduce false alarms" |
| ) |
|
|
| |
| |
| |
| input_col, result_col = st.columns([2.2, 1.2]) |
|
|
| |
| |
| |
| with input_col: |
| st.subheader("🧮 Engine Sensor Inputs") |
|
|
| c1, c2 = st.columns(2) |
|
|
| with c1: |
| engine_rpm = st.number_input("Engine RPM", value=1500.0) |
| lub_oil_pressure = st.number_input("Lub Oil Pressure", value=4.0) |
| fuel_pressure = st.number_input("Fuel Pressure", value=3.5) |
|
|
| with c2: |
| coolant_pressure = st.number_input("Coolant Pressure", value=2.5) |
| lub_oil_temp = st.number_input("Lub Oil Temp (°C)", value=85.0) |
| coolant_temp = st.number_input("Coolant Temp (°C)", value=90.0) |
|
|
| predict_btn = st.button("🔍 Predict Engine Health", use_container_width=False) |
|
|
| |
| |
| |
| with result_col: |
| st.subheader("📊 Prediction Result") |
|
|
| with st.container(border=True): |
| if predict_btn: |
| input_df = pd.DataFrame([{ |
| "engine_rpm": engine_rpm, |
| "lub_oil_pressure": lub_oil_pressure, |
| "fuel_pressure": fuel_pressure, |
| "coolant_pressure": coolant_pressure, |
| "lub_oil_temp": lub_oil_temp, |
| "coolant_temp": coolant_temp |
| }]) |
|
|
| |
| |
| payload = input_df.iloc[0].to_dict() |
| response = requests.post ( |
| "https://asvravi-asv-predictive-maintenance-backend.hf.space/v1/PredictiveMaintenance", |
| json=payload |
| ) |
| if response.status_code == 200: |
| result = response.json () |
| fault_prob = result.get ("fault_probability") |
| else: |
| st.error (f"Error in API request - {response.status_code}") |
|
|
| |
| prediction = 1 if fault_prob >= threshold else 0 |
|
|
| if prediction == 1: |
| st.error( |
| f"⚠️ **FAULT LIKELY**\n\n" |
| f"Estimated Fault Probability: **{fault_prob:.2f}**\n\n" |
| "Immediate inspection or preventive maintenance is recommended." |
| ) |
| else: |
| st.success( |
| f"✅ **ENGINE HEALTHY**\n\n" |
| f"Estimated Fault Probability: **{fault_prob:.2f}**\n\n" |
| "No immediate maintenance action is required." |
| ) |
|
|
| |
| |
| |
| st.markdown("---") |
| st.caption( |
| "Model: Tuned XGBoost | Objective: Predictive Maintenance | " |
| "Optimized for high fault recall to reduce missed failures" |
| ) |
|
|