charantejapolavarapu commited on
Commit
b4a5e8d
·
verified ·
1 Parent(s): 9690799

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -87
app.py CHANGED
@@ -5,101 +5,54 @@ 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")
 
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.")