File size: 2,682 Bytes
52c06b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633dcba
52c06b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633dcba
 
 
 
 
52c06b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633dcba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download


# ==============================
# PAGE CONFIG
# ==============================

st.set_page_config(
    page_title="Engine Failure Prediction",
    layout="centered"
)


# ==============================
# LOAD MODEL
# ==============================

@st.cache_resource
def load_model():
    try:
        model_path = hf_hub_download(
            repo_id="Rizwan9/Engine_Failure_Model",
            filename="best_engine_model.pkl"
        )
        return joblib.load(model_path)
    except Exception as e:
        st.error(f"Error loading model: {e}")
        return None


with st.spinner("Loading model..."):
    model = load_model()

if model is None:
    st.stop()


# ==============================
# UI
# ==============================

st.title("🔧 Engine Failure Prediction System")

st.write("""
This application predicts whether an engine is likely to **fail** based on sensor readings.

Helps maintenance teams take preventive action.
""")


# ==============================
# INPUTS
# ==============================

engine_rpm = st.number_input("Engine RPM", 500, 5000, 1500)
lub_oil_pressure = st.number_input("Lubrication Oil Pressure", 0.0, 10.0, 3.5)
fuel_pressure = st.number_input("Fuel Pressure", 0.0, 10.0, 4.0)
coolant_pressure = st.number_input("Coolant Pressure", 0.0, 10.0, 2.5)
lub_oil_temp = st.number_input("Lubrication Oil Temperature", 50.0, 150.0, 90.0)
coolant_temp = st.number_input("Coolant Temperature", 50.0, 150.0, 85.0)


# ==============================
# PREDICTION
# ==============================

if st.button("Predict Engine Condition"):

    try:
        # FIXED COLUMN ORDER
        columns = [
            "Engine rpm",
            "Lub oil pressure",
            "Fuel pressure",
            "Coolant pressure",
            "Lub oil temp",
            "Coolant temp"
        ]

        input_data = pd.DataFrame([[
            engine_rpm,
            lub_oil_pressure,
            fuel_pressure,
            coolant_pressure,
            lub_oil_temp,
            coolant_temp
        ]], columns=columns)

        prediction = model.predict(input_data)[0]

        st.subheader("Prediction Result")

        # Optional probability
        if hasattr(model, "predict_proba"):
            prob = model.predict_proba(input_data)[0][1]
            st.write(f"Failure Probability: {prob:.2f}")

        if prediction == 1:
            st.error("Engine Failure Likely – Maintenance Required")
        else:
            st.success("Engine Operating Normally")

    except Exception as e:
        st.error(f"Prediction failed: {e}")