Debashre2824's picture
Upload app.py with huggingface_hub
d4d9252 verified
import streamlit as st
import joblib
import numpy as np
import pandas as pd
# Set page configuration
st.set_page_config(
page_title="Engine Predictive Maintenance",
page_icon="⚙️",
layout="wide"
)
# Load the trained model
@st.cache_resource
def load_model():
model = joblib.load('best_xgboost_model.pkl')
return model
model = load_model()
# Title and description
st.title("⚙️ Engine Predictive Maintenance System")
st.markdown("""
This application predicts whether an engine is **Normal** or **Faulty** based on sensor readings.
Enter the sensor values below to get a prediction.
""")
# Create two columns for better layout
col1, col2 = st.columns(2)
with col1:
st.subheader("📊 Input Sensor Readings")
# Input fields for the 6 features
engine_rpm = st.number_input(
"Engine RPM",
min_value=0.0,
max_value=10000.0,
value=2000.0,
step=100.0,
help="Engine Revolutions Per Minute"
)
lub_oil_pressure = st.number_input(
"Lub Oil Pressure (psi)",
min_value=0.0,
max_value=200.0,
value=50.0,
step=1.0,
help="Lubricating Oil Pressure"
)
fuel_pressure = st.number_input(
"Fuel Pressure (psi)",
min_value=0.0,
max_value=200.0,
value=50.0,
step=1.0,
help="Fuel Pressure"
)
with col2:
st.subheader("🌡️ Temperature & Pressure")
coolant_pressure = st.number_input(
"Coolant Pressure (psi)",
min_value=0.0,
max_value=200.0,
value=50.0,
step=1.0,
help="Coolant Pressure"
)
lub_oil_temp = st.number_input(
"Lub Oil Temperature (°C)",
min_value=0.0,
max_value=200.0,
value=80.0,
step=1.0,
help="Lubricating Oil Temperature"
)
coolant_temp = st.number_input(
"Coolant Temperature (°C)",
min_value=0.0,
max_value=150.0,
value=70.0,
step=1.0,
help="Coolant Temperature"
)
# Predict button
if st.button("🔍 Predict Engine Condition", type="primary"):
# Create input array with the correct feature order
input_data = np.array([[
engine_rpm,
lub_oil_pressure,
fuel_pressure,
coolant_pressure,
lub_oil_temp,
coolant_temp
]])
# Make prediction
prediction = model.predict(input_data)[0]
prediction_proba = model.predict_proba(input_data)[0]
# Display results
st.markdown("---")
st.subheader("Prediction Result")
if prediction == 0:
st.success("**Engine Status: NORMAL**")
st.metric("Confidence", f"{prediction_proba[0]*100:.2f}%")
st.info("The engine is operating within normal parameters. Continue regular maintenance schedule.")
else:
st.error("**Engine Status: FAULTY**")
st.metric("Confidence", f"{prediction_proba[1]*100:.2f}%")
st.warning("The engine shows signs of potential failure. Immediate inspection recommended!")
# Show probability distribution
st.markdown("### Prediction Probabilities")
prob_df = pd.DataFrame({
'Condition': ['Normal', 'Faulty'],
'Probability': [prediction_proba[0], prediction_proba[1]]
})
st.bar_chart(prob_df.set_index('Condition'))
# Add footer with information
st.markdown("---")
st.markdown("""
**Model Information:**
- Algorithm: XGBoost Classifier
- F1-Score: 0.7630
- Recall: 87.01%
- Training Dataset: 19,535 engine records
**Features Used:**
1. Engine RPM
2. Lubricating Oil Pressure
3. Fuel Pressure
4. Coolant Pressure
5. Lubricating Oil Temperature
6. Coolant Temperature
""")