Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,143 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
from huggingface_hub import hf_hub_download
|
| 4 |
import joblib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
coolant_temp = st.number_input("Coolant Temperature (°C)", min_value=0.67, value=128.60, step=0.01)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
#
|
|
|
|
|
|
|
| 28 |
input_data = pd.DataFrame([{
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
}])
|
| 36 |
|
| 37 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
classification_threshold = 0.45
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
st.success(
|
| 47 |
-
|
|
|
|
| 48 |
)
|
| 49 |
else:
|
| 50 |
st.error(
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
%%writefile mlops/deployment/app.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
import joblib
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
|
| 8 |
+
# --------------------------------------------------
|
| 9 |
+
# Page Configuration
|
| 10 |
+
# --------------------------------------------------
|
| 11 |
+
st.set_page_config(
|
| 12 |
+
page_title="Predictive Maintenance | Engine Health",
|
| 13 |
+
page_icon="🛠️",
|
| 14 |
+
layout="centered"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# --------------------------------------------------
|
| 18 |
+
# Load Model (cached)
|
| 19 |
+
# --------------------------------------------------
|
| 20 |
+
@st.cache_resource
|
| 21 |
+
def load_model():
|
| 22 |
+
model_path = hf_hub_download(
|
| 23 |
+
repo_id="csankaran3/engine-condition-prediction",
|
| 24 |
+
filename="best_engine_condition_prediction_model_v1.joblib"
|
| 25 |
+
)
|
| 26 |
+
return joblib.load(model_path)
|
| 27 |
+
|
| 28 |
+
model = load_model()
|
| 29 |
+
|
| 30 |
+
# --------------------------------------------------
|
| 31 |
+
# Header
|
| 32 |
+
# --------------------------------------------------
|
| 33 |
+
st.title("🛠️ Predictive Maintenance – Engine Condition")
|
| 34 |
+
st.markdown(
|
| 35 |
+
"""
|
| 36 |
+
This **internal diagnostic tool** helps automobile companies
|
| 37 |
+
predict **engine health (Active / Faulty)** using real-time sensor values.
|
| 38 |
+
"""
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
st.divider()
|
| 42 |
+
|
| 43 |
+
# --------------------------------------------------
|
| 44 |
+
# Sidebar – Sensor Inputs
|
| 45 |
+
# --------------------------------------------------
|
| 46 |
+
st.sidebar.header("📊 Sensor Inputs")
|
| 47 |
+
|
| 48 |
+
engine_rpm = st.sidebar.number_input(
|
| 49 |
+
"Engine RPM",
|
| 50 |
+
min_value=0.0,
|
| 51 |
+
value=1150.0,
|
| 52 |
+
step=10.0,
|
| 53 |
+
help="Rotational speed of the engine"
|
| 54 |
+
)
|
| 55 |
|
| 56 |
+
lub_oil_pressure = st.sidebar.number_input(
|
| 57 |
+
"Lub Oil Pressure (kPa)",
|
| 58 |
+
min_value=0.0,
|
| 59 |
+
value=3.63,
|
| 60 |
+
step=0.01
|
| 61 |
+
)
|
| 62 |
|
| 63 |
+
fuel_pressure = st.sidebar.number_input(
|
| 64 |
+
"Fuel Pressure (kPa)",
|
| 65 |
+
min_value=0.0,
|
| 66 |
+
value=10.57,
|
| 67 |
+
step=0.01
|
| 68 |
+
)
|
| 69 |
|
| 70 |
+
coolant_pressure = st.sidebar.number_input(
|
| 71 |
+
"Coolant Pressure (kPa)",
|
| 72 |
+
min_value=0.0,
|
| 73 |
+
value=7.48,
|
| 74 |
+
step=0.01
|
| 75 |
+
)
|
| 76 |
|
| 77 |
+
lub_oil_temp = st.sidebar.number_input(
|
| 78 |
+
"Lub Oil Temperature (°C)",
|
| 79 |
+
min_value=0.0,
|
| 80 |
+
value=89.58,
|
| 81 |
+
step=0.01
|
| 82 |
+
)
|
|
|
|
| 83 |
|
| 84 |
+
coolant_temp = st.sidebar.number_input(
|
| 85 |
+
"Coolant Temperature (°C)",
|
| 86 |
+
min_value=0.0,
|
| 87 |
+
value=128.60,
|
| 88 |
+
step=0.01
|
| 89 |
+
)
|
| 90 |
|
| 91 |
+
# --------------------------------------------------
|
| 92 |
+
# Prepare Input Data
|
| 93 |
+
# --------------------------------------------------
|
| 94 |
input_data = pd.DataFrame([{
|
| 95 |
+
"Engine rpm": engine_rpm,
|
| 96 |
+
"Lub oil pressure": lub_oil_pressure,
|
| 97 |
+
"Fuel pressure": fuel_pressure,
|
| 98 |
+
"Coolant pressure": coolant_pressure,
|
| 99 |
+
"lub oil temp": lub_oil_temp,
|
| 100 |
+
"Coolant temp": coolant_temp
|
| 101 |
}])
|
| 102 |
|
| 103 |
+
# --------------------------------------------------
|
| 104 |
+
# Prediction Section
|
| 105 |
+
# --------------------------------------------------
|
| 106 |
+
st.subheader("🔍 Engine Condition Prediction")
|
| 107 |
+
|
| 108 |
classification_threshold = 0.45
|
| 109 |
|
| 110 |
+
if st.button("🚀 Predict Engine Condition", use_container_width=True):
|
| 111 |
+
with st.spinner("Analyzing sensor data..."):
|
| 112 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 113 |
+
prediction = int(prediction_proba >= classification_threshold)
|
| 114 |
+
|
| 115 |
+
st.divider()
|
| 116 |
+
|
| 117 |
+
col1, col2 = st.columns(2)
|
| 118 |
+
|
| 119 |
+
with col1:
|
| 120 |
+
st.metric(
|
| 121 |
+
label="Fault Probability",
|
| 122 |
+
value=f"{prediction_proba:.2%}"
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
with col2:
|
| 126 |
+
st.metric(
|
| 127 |
+
label="Threshold",
|
| 128 |
+
value=f"{classification_threshold:.0%}"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
st.divider()
|
| 132 |
+
|
| 133 |
+
if prediction == 1:
|
| 134 |
st.success(
|
| 135 |
+
"✅ **Engine Status: ACTIVE**\n\n"
|
| 136 |
+
"The engine is operating within safe parameters."
|
| 137 |
)
|
| 138 |
else:
|
| 139 |
st.error(
|
| 140 |
+
"⚠️ **Engine Status: FAULTY**\n\n"
|
| 141 |
+
"Potential fault detected. Immediate inspection recommended."
|
| 142 |
+
)
|
| 143 |
+
)
|