charantejapolavarapu commited on
Commit
79210e3
·
verified ·
1 Parent(s): 89d76a3

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -113
app.py DELETED
@@ -1,113 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import joblib
4
- import numpy as np
5
- import plotly.graph_objects as go
6
- import os
7
- import xgboost as xgb
8
-
9
- # 1. PAGE SETUP
10
- st.set_page_config(page_title="Jet Engine AI Predictor", page_icon="✈️", layout="wide")
11
-
12
- # 2. AUTO-TRAINING LOGIC (Fixes the "Missing File" or "Corrupted File" issue)
13
- def train_and_save_model():
14
- with st.spinner("Training the AI model for the first time... please wait."):
15
- # Load Data from NASA Repository
16
- url = "https://raw.githubusercontent.com/datasets-machine-learning/nasa-turbofan-failure-prediction/master/data/train_FD001.txt"
17
- cols = ['unit', 'cycles', 'os1', 'os2', 'os3'] + [f's{i}' for i in range(1, 22)]
18
- df = pd.read_csv(url, sep='\s+', header=None, names=cols)
19
-
20
- # Calculate RUL (Target)
21
- max_cycles = df.groupby('unit')['cycles'].max().reset_index()
22
- max_cycles.columns = ['unit', 'max_of_unit']
23
- df = df.merge(max_cycles, on='unit', how='left')
24
- df['RUL'] = df['max_of_unit'] - df['cycles']
25
-
26
- # Select Features (15 columns)
27
- features = ['cycles', 's2', 's3', 's4', 's7', 's8', 's11', 's12', 's13', 's15', 's17', 's20', 's21', 'os1', 'os2']
28
- X = df[features]
29
- y = df['RUL']
30
-
31
- # Train XGBoost
32
- model = xgb.XGBRegressor(n_estimators=100, learning_rate=0.1, max_depth=5)
33
- model.fit(X, y)
34
-
35
- # Save locally in the HF Space
36
- joblib.dump(model, 'engine_model.pkl')
37
- return model
38
-
39
- @st.cache_resource
40
- def load_model():
41
- if os.path.exists('engine_model.pkl'):
42
- try:
43
- return joblib.load('engine_model.pkl')
44
- except:
45
- # If the file is corrupted (like the mport error), re-train it
46
- return train_and_save_model()
47
- else:
48
- return train_and_save_model()
49
-
50
- # Load model on startup
51
- model = load_model()
52
-
53
- # 3. UI LAYOUT
54
- st.title("✈️ Jet Engine Predictive Maintenance System")
55
- st.markdown("---")
56
-
57
- col1, col2 = st.columns([1, 2])
58
-
59
- with col1:
60
- st.header("📥 Sensor Inputs")
61
- st.write("Adjust sliders to simulate engine conditions:")
62
-
63
- # Inputs
64
- cycle = st.slider("Current Cycles", 1, 350, 100)
65
- s2 = st.slider("Temp (S2)", 640.0, 650.0, 642.5)
66
- s3 = st.slider("Temp (S3)", 1580.0, 1600.0, 1589.0)
67
- s4 = st.slider("Pressure (S4)", 1400.0, 1430.0, 1408.0)
68
- s7 = st.slider("Pressure (S7)", 550.0, 560.0, 553.5)
69
- s11 = st.slider("Speed (S11)", 47.0, 48.5, 47.5)
70
-
71
- # Analyze Button
72
- predict_btn = st.button("Predict Engine Health", type="primary")
73
-
74
- with col2:
75
- st.header("📊 Prediction Result")
76
-
77
- if predict_btn:
78
- # Prepare inputs (must be 15 values to match model training)
79
- # Using some static defaults for the other 9 features to keep UI simple
80
- sample_input = np.array([[cycle, s2, s3, s4, s7, 550, s11, 2388, 521, 8.4, 392, 39, 23, 0.001, 0.0002]])
81
-
82
- # Make Prediction
83
- prediction = model.predict(sample_input)
84
- rul = int(max(0, prediction[0]))
85
-
86
- # Gauge Chart
87
- fig = go.Figure(go.Indicator(
88
- mode = "gauge+number",
89
- value = rul,
90
- title = {'text': "Remaining Useful Life (Cycles)"},
91
- gauge = {
92
- 'axis': {'range': [0, 200]},
93
- 'steps' : [
94
- {'range': [0, 30], 'color': "red"},
95
- {'range': [30, 80], 'color': "orange"},
96
- {'range': [80, 200], 'color': "green"}],
97
- 'bar': {'color': "black"}
98
- }
99
- ))
100
- st.plotly_chart(fig)
101
-
102
- # Status Message
103
- if rul < 30:
104
- st.error(f"🚨 CRITICAL: Engine failure likely in {rul} cycles!")
105
- elif rul < 80:
106
- st.warning(f"⚠️ CAUTION: Maintenance check required within {rul} cycles.")
107
- else:
108
- st.success(f"✅ HEALTHY: Engine is safe for {rul} more cycles.")
109
- else:
110
- st.info("Adjust the sliders and click 'Predict' to see the results.")
111
-
112
- st.markdown("---")
113
- st.caption("B.Tech AI&DS Project | Dataset: NASA C-MAPSS")