charantejapolavarapu commited on
Commit
41fdc19
·
verified ·
1 Parent(s): 1c6ce9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -41
app.py CHANGED
@@ -3,68 +3,103 @@ import pandas as pd
3
  import joblib
4
  import numpy as np
5
  import plotly.graph_objects as go
 
6
 
7
- # Set Page Config
8
- st.set_page_config(page_title="AI Predictive Maintenance", layout="wide")
 
 
 
 
9
 
10
- # Load Model
11
  @st.cache_resource
12
  def load_model():
13
- return joblib.load('engine_model.pkl')
 
 
 
14
 
15
  model = load_model()
16
 
17
- st.title("✈️ Smart Maintenance: Jet Engine RUL Predictor")
18
- st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- # Layout: 2 Columns
21
- col1, col2 = st.columns([1, 2])
22
 
23
- with col1:
24
- st.header("📥 Sensor Inputs")
25
- cycle = st.slider("Current Flight Cycles", 1, 350, 100)
26
- s2 = st.number_input("Sensor 2 (LPC Outlet Temp)", value=642.0)
27
- s3 = st.number_input("Sensor 3 (HPC Outlet Temp)", value=1585.0)
28
- s4 = st.number_input("Sensor 4 (LPT Outlet Temp)", value=1405.0)
29
- s7 = st.number_input("Sensor 7 (HPC Outlet Press)", value=553.0)
30
- s11 = st.number_input("Sensor 11 (HPC Speed)", value=47.5)
31
 
32
- # Static values for remaining features to simplify UI
33
- other_features = [550, 2388, 521, 8.4, 392, 39, 23]
 
34
 
35
- if st.button("Analyze Engine Health", type="primary"):
36
- inputs = np.array([[cycle, s2, s3, s4, s7, s11] + other_features])
37
- prediction = model.predict(inputs)[0]
38
- st.session_state['prediction'] = max(0, int(prediction))
39
 
40
- with col2:
41
- st.header("📊 Diagnostic Results")
42
- if 'prediction' in st.session_state:
43
- rul = st.session_state['prediction']
44
-
45
- # 1. Visual Gauge Chart
46
  fig = go.Figure(go.Indicator(
47
  mode = "gauge+number",
48
  value = rul,
49
- title = {'text': "Remaining Useful Life (Cycles)"},
 
50
  gauge = {
51
- 'axis': {'range': [0, 200]},
52
- 'bar': {'color': "black"},
53
- 'steps' : [
54
  {'range': [0, 30], 'color': "red"},
55
- {'range': [30, 70], 'color': "yellow"},
56
- {'range': [70, 200], 'color': "green"}],
 
 
 
 
57
  }
58
  ))
59
  st.plotly_chart(fig)
60
 
61
- # 2. Status Logic
62
- if rul < 30:
63
- st.error(f"CRITICAL: Engine failure likely within {rul} cycles. Ground the aircraft immediately!")
64
- elif rul < 70:
65
- st.warning(f"CAUTION: Maintenance due soon. Estimated life: {rul} cycles.")
 
66
  else:
67
- st.success(f"HEALTHY: Engine is operating within safe parameters ({rul} cycles remaining).")
 
 
 
 
 
68
 
 
69
  st.markdown("---")
70
- st.info("B.Tech AI&DS Special Project: Industrial Time-Series Forecasting")
 
3
  import joblib
4
  import numpy as np
5
  import plotly.graph_objects as go
6
+ import os
7
 
8
+ # --- PAGE CONFIGURATION ---
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
+ model_path = 'engine_model.pkl'
19
+ if not os.path.exists(model_path):
20
+ return None
21
+ return joblib.load(model_path)
22
 
23
  model = load_model()
24
 
25
+ # --- UI HEADER ---
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("⚠️ **Model file 'engine_model.pkl' not found!**")
35
+ st.info("Please upload the `engine_model.pkl` file you generated locally to the 'Files and versions' tab.")
36
+ st.stop()
37
+
38
+ # --- SIDEBAR INPUTS ---
39
+ st.sidebar.header("🛠️ Input Sensor Data")
40
+ st.sidebar.markdown("Adjust the sliders based on engine telemetry:")
41
+
42
+ # Feature list: ['cycles', 's2', 's3', 's4', 's7', 's8', 's11', 's12', 's13', 's15', 's17', 's20', 's21']
43
+ cycle = st.sidebar.slider("Current Operational Cycle", 1, 350, 100)
44
+ s2 = st.sidebar.slider("Sensor 2 (LPC Outlet Temp)", 640.0, 650.0, 642.5)
45
+ s3 = st.sidebar.slider("Sensor 3 (HPC Outlet Temp)", 1580.0, 1600.0, 1589.0)
46
+ s4 = st.sidebar.slider("Sensor 4 (LPT Outlet Temp)", 1400.0, 1430.0, 1408.0)
47
+ s7 = st.sidebar.slider("Sensor 7 (HPC Outlet Press)", 550.0, 560.0, 553.5)
48
+ s11 = st.sidebar.slider("Sensor 11 (HPC Speed)", 47.0, 48.5, 47.5)
49
 
50
+ # Hidden features (filled with mean values to keep UI clean)
51
+ other_features = [550, 2388, 521, 8.4, 392, 39, 23]
52
 
53
+ # --- PREDICTION LOGIC ---
54
+ st.markdown("### 🔍 Diagnostic Analysis")
55
+
56
+ if st.button("Run AI Prediction", type="primary"):
57
+ # Prepare input array (Must match training features exactly)
58
+ input_data = np.array([[cycle, s2, s3, s4, s7, 1300, s11, 550, 2388, 521, 8.4, 392, 39, 23, 1]])
 
 
59
 
60
+ # Take only the first 15 features as defined in training
61
+ prediction = model.predict(input_data[:, :15])
62
+ rul = max(0, int(prediction[0]))
63
 
64
+ # --- RESULTS DISPLAY ---
65
+ col1, col2 = st.columns([1, 1])
 
 
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")