Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,101 +5,54 @@ import numpy as np
|
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
st.set_page_config(
|
| 10 |
-
page_title="Jet Engine AI Predictor",
|
| 11 |
-
page_icon="✈️",
|
| 12 |
-
layout="wide"
|
| 13 |
-
)
|
| 14 |
|
| 15 |
-
# --- MODEL LOADING WITH SAFETY CHECK ---
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return joblib.load(model_path)
|
| 22 |
|
| 23 |
model = load_model()
|
| 24 |
|
| 25 |
-
|
| 26 |
-
st.title("✈️ Jet Engine Predictive Maintenance System")
|
| 27 |
-
st.markdown("""
|
| 28 |
-
This AI model predicts the **Remaining Useful Life (RUL)** of a turbofan engine based on sensor readings.
|
| 29 |
-
It helps engineers decide when to perform maintenance *before* a failure occurs.
|
| 30 |
-
""")
|
| 31 |
|
| 32 |
-
# Check if model is loaded, if not, show instructions
|
| 33 |
if model is None:
|
| 34 |
-
st.error("
|
| 35 |
-
st.info("Please upload the `engine_model.pkl` file you generated locally to the 'Files and versions' tab.")
|
| 36 |
st.stop()
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
st.sidebar.header("
|
| 40 |
-
st.sidebar.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
rul
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
with col1:
|
| 68 |
-
# Gauge Chart
|
| 69 |
-
fig = go.Figure(go.Indicator(
|
| 70 |
-
mode = "gauge+number",
|
| 71 |
-
value = rul,
|
| 72 |
-
domain = {'x': [0, 1], 'y': [0, 1]},
|
| 73 |
-
title = {'text': "Estimated Cycles Remaining", 'font': {'size': 24}},
|
| 74 |
-
gauge = {
|
| 75 |
-
'axis': {'range': [0, 200], 'tickwidth': 1},
|
| 76 |
-
'bar': {'color': "darkblue"},
|
| 77 |
-
'steps': [
|
| 78 |
-
{'range': [0, 30], 'color': "red"},
|
| 79 |
-
{'range': [30, 75], 'color': "orange"},
|
| 80 |
-
{'range': [75, 200], 'color': "green"}],
|
| 81 |
-
'threshold': {
|
| 82 |
-
'line': {'color': "black", 'width': 4},
|
| 83 |
-
'thickness': 0.75,
|
| 84 |
-
'value': rul}
|
| 85 |
-
}
|
| 86 |
-
))
|
| 87 |
-
st.plotly_chart(fig)
|
| 88 |
-
|
| 89 |
-
with col2:
|
| 90 |
-
st.write("### Engine Health Status")
|
| 91 |
-
if rul <= 30:
|
| 92 |
-
st.error(f"🚨 **CRITICAL STATE**\n\nEngine failure predicted within **{rul} cycles**. Maintenance required immediately.")
|
| 93 |
-
elif rul <= 75:
|
| 94 |
-
st.warning(f"⚠️ **CAUTION**\n\nEngine showing signs of wear. Estimated life: **{rul} cycles**. Schedule inspection soon.")
|
| 95 |
-
else:
|
| 96 |
-
st.success(f"✅ **HEALTHY**\n\nEngine operating normally. Estimated life: **{rul} cycles**.")
|
| 97 |
-
|
| 98 |
-
st.info("**Note:** RUL (Remaining Useful Life) is an estimate based on simulation data patterns.")
|
| 99 |
-
|
| 100 |
-
else:
|
| 101 |
-
st.write("Click the button on the left to analyze the current sensor inputs.")
|
| 102 |
-
|
| 103 |
-
# --- FOOTER ---
|
| 104 |
-
st.markdown("---")
|
| 105 |
-
st.caption("B.Tech AI & Data Science Special Project | Developed for Industrial Predictive Maintenance")
|
|
|
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# Page Config
|
| 9 |
+
st.set_page_config(page_title="Jet Engine AI", page_icon="✈️")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 11 |
@st.cache_resource
|
| 12 |
def load_model():
|
| 13 |
+
if os.path.exists('engine_model.pkl'):
|
| 14 |
+
return joblib.load('engine_model.pkl')
|
| 15 |
+
return None
|
|
|
|
| 16 |
|
| 17 |
model = load_model()
|
| 18 |
|
| 19 |
+
st.title("✈️ Predictive Maintenance Dashboard")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
if model is None:
|
| 22 |
+
st.error("Model file 'engine_model.pkl' not found. Please upload it.")
|
|
|
|
| 23 |
st.stop()
|
| 24 |
|
| 25 |
+
# Sidebar for Inputs
|
| 26 |
+
st.sidebar.header("Sensor Data Input")
|
| 27 |
+
cycle = st.sidebar.slider("Operational Cycle", 1, 350, 100)
|
| 28 |
+
s2 = st.sidebar.number_input("Sensor 2 (Temp)", value=642.0)
|
| 29 |
+
s3 = st.sidebar.number_input("Sensor 3 (Temp)", value=1589.0)
|
| 30 |
+
s4 = st.sidebar.number_input("Sensor 4 (Pressure)", value=1408.0)
|
| 31 |
+
s7 = st.sidebar.number_input("Sensor 7 (HPC Press)", value=553.0)
|
| 32 |
+
s11 = st.sidebar.number_input("Sensor 11 (Speed)", value=47.5)
|
| 33 |
+
|
| 34 |
+
if st.button("Predict Engine Health"):
|
| 35 |
+
# Create input array (matches the 15 features in training)
|
| 36 |
+
# Filling remaining slots with defaults for simplicity
|
| 37 |
+
inputs = np.array([[cycle, s2, s3, s4, s7, 550, s11, 2388, 521, 8.4, 392, 39, 23, 0.001, 0.0002]])
|
| 38 |
+
prediction = model.predict(inputs)
|
| 39 |
+
rul = int(max(0, prediction[0]))
|
| 40 |
+
|
| 41 |
+
# Gauge Chart
|
| 42 |
+
fig = go.Figure(go.Indicator(
|
| 43 |
+
mode = "gauge+number",
|
| 44 |
+
value = rul,
|
| 45 |
+
title = {'text': "Remaining Useful Life (Cycles)"},
|
| 46 |
+
gauge = {'axis': {'range': [0, 200]},
|
| 47 |
+
'steps' : [
|
| 48 |
+
{'range': [0, 30], 'color': "red"},
|
| 49 |
+
{'range': [30, 80], 'color': "orange"},
|
| 50 |
+
{'range': [80, 200], 'color': "green"}]}))
|
| 51 |
+
st.plotly_chart(fig)
|
| 52 |
|
| 53 |
+
if rul < 30:
|
| 54 |
+
st.error("🚨 CRITICAL: Maintenance Required Immediately!")
|
| 55 |
+
elif rul < 80:
|
| 56 |
+
st.warning("⚠️ CAUTION: Schedule Maintenance Soon.")
|
| 57 |
+
else:
|
| 58 |
+
st.success("✅ HEALTHY: Engine is in good condition.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|