File size: 2,097 Bytes
4c99537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import streamlit as st
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib

# -----------------------------
# Load pipeline model
# -----------------------------
model_path = hf_hub_download(
    repo_id="Rajanan/model-predictive-engine-maintenance",
    filename="best_engine_failure_model.joblib",
    repo_type="model"
)

model = joblib.load(model_path)

# -----------------------------
# UI
# -----------------------------
st.title("Predictive Engine Maintenance System")

st.markdown("""
Predict whether an engine requires maintenance based on sensor inputs.
""")

# -----------------------------
# User Inputs
# -----------------------------
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=3000, value=800)

lub_oil_pressure = st.number_input("Lub Oil Pressure", min_value=0.0, max_value=10.0, value=3.0)

fuel_pressure = st.number_input("Fuel Pressure", min_value=0.0, max_value=25.0, value=6.0)

coolant_pressure = st.number_input("Coolant Pressure", min_value=0.0, max_value=10.0, value=2.0)

lub_oil_temp = st.number_input("Lub Oil Temperature (°C)", min_value=50.0, max_value=120.0, value=75.0)

coolant_temp = st.number_input("Coolant Temperature (°C)", min_value=50.0, max_value=200.0, value=80.0)

# -----------------------------
# Create input DataFrame
# -----------------------------
input_data = pd.DataFrame([{
    "Engine rpm": engine_rpm,
    "Lub oil pressure": lub_oil_pressure,
    "Fuel pressure": fuel_pressure,
    "Coolant pressure": coolant_pressure,
    "lub oil temp": lub_oil_temp,
    "Coolant temp": coolant_temp
}])

# -----------------------------
# Prediction with threshold
# -----------------------------
if st.button("Predict Engine Condition"):

    # Probability
    prob = model.predict_proba(input_data)[0][1]

    # SAME threshold used in training
    threshold = 0.4

    prediction = 1 if prob >= threshold else 0

    st.write(f"Failure Probability: {prob:.2f}")

    if prediction == 1:
        st.error("Engine likely requires maintenance!")
    else:
        st.success("Engine operating normally")