charantejapolavarapu's picture
Update app.py
41fdc19 verified
raw
history blame
4.03 kB
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import plotly.graph_objects as go
import os
# --- PAGE CONFIGURATION ---
st.set_page_config(
page_title="Jet Engine AI Predictor",
page_icon="✈️",
layout="wide"
)
# --- MODEL LOADING WITH SAFETY CHECK ---
@st.cache_resource
def load_model():
model_path = 'engine_model.pkl'
if not os.path.exists(model_path):
return None
return joblib.load(model_path)
model = load_model()
# --- UI HEADER ---
st.title("✈️ Jet Engine Predictive Maintenance System")
st.markdown("""
This AI model predicts the **Remaining Useful Life (RUL)** of a turbofan engine based on sensor readings.
It helps engineers decide when to perform maintenance *before* a failure occurs.
""")
# Check if model is loaded, if not, show instructions
if model is None:
st.error("⚠️ **Model file 'engine_model.pkl' not found!**")
st.info("Please upload the `engine_model.pkl` file you generated locally to the 'Files and versions' tab.")
st.stop()
# --- SIDEBAR INPUTS ---
st.sidebar.header("🛠️ Input Sensor Data")
st.sidebar.markdown("Adjust the sliders based on engine telemetry:")
# Feature list: ['cycles', 's2', 's3', 's4', 's7', 's8', 's11', 's12', 's13', 's15', 's17', 's20', 's21']
cycle = st.sidebar.slider("Current Operational Cycle", 1, 350, 100)
s2 = st.sidebar.slider("Sensor 2 (LPC Outlet Temp)", 640.0, 650.0, 642.5)
s3 = st.sidebar.slider("Sensor 3 (HPC Outlet Temp)", 1580.0, 1600.0, 1589.0)
s4 = st.sidebar.slider("Sensor 4 (LPT Outlet Temp)", 1400.0, 1430.0, 1408.0)
s7 = st.sidebar.slider("Sensor 7 (HPC Outlet Press)", 550.0, 560.0, 553.5)
s11 = st.sidebar.slider("Sensor 11 (HPC Speed)", 47.0, 48.5, 47.5)
# Hidden features (filled with mean values to keep UI clean)
other_features = [550, 2388, 521, 8.4, 392, 39, 23]
# --- PREDICTION LOGIC ---
st.markdown("### 🔍 Diagnostic Analysis")
if st.button("Run AI Prediction", type="primary"):
# Prepare input array (Must match training features exactly)
input_data = np.array([[cycle, s2, s3, s4, s7, 1300, s11, 550, 2388, 521, 8.4, 392, 39, 23, 1]])
# Take only the first 15 features as defined in training
prediction = model.predict(input_data[:, :15])
rul = max(0, int(prediction[0]))
# --- RESULTS DISPLAY ---
col1, col2 = st.columns([1, 1])
with col1:
# Gauge Chart
fig = go.Figure(go.Indicator(
mode = "gauge+number",
value = rul,
domain = {'x': [0, 1], 'y': [0, 1]},
title = {'text': "Estimated Cycles Remaining", 'font': {'size': 24}},
gauge = {
'axis': {'range': [0, 200], 'tickwidth': 1},
'bar': {'color': "darkblue"},
'steps': [
{'range': [0, 30], 'color': "red"},
{'range': [30, 75], 'color': "orange"},
{'range': [75, 200], 'color': "green"}],
'threshold': {
'line': {'color': "black", 'width': 4},
'thickness': 0.75,
'value': rul}
}
))
st.plotly_chart(fig)
with col2:
st.write("### Engine Health Status")
if rul <= 30:
st.error(f"🚨 **CRITICAL STATE**\n\nEngine failure predicted within **{rul} cycles**. Maintenance required immediately.")
elif rul <= 75:
st.warning(f"⚠️ **CAUTION**\n\nEngine showing signs of wear. Estimated life: **{rul} cycles**. Schedule inspection soon.")
else:
st.success(f"✅ **HEALTHY**\n\nEngine operating normally. Estimated life: **{rul} cycles**.")
st.info("**Note:** RUL (Remaining Useful Life) is an estimate based on simulation data patterns.")
else:
st.write("Click the button on the left to analyze the current sensor inputs.")
# --- FOOTER ---
st.markdown("---")
st.caption("B.Tech AI & Data Science Special Project | Developed for Industrial Predictive Maintenance")