File size: 2,887 Bytes
ae5b70e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7629ca
 
d604bc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae5b70e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b0e5b4
ae5b70e
 
 
d7629ca
 
 
 
 
 
 
 
2048fb4
d7629ca
 
 
 
 
 
 
2048fb4
d7629ca
 
 
 
 
 
 
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download

st.set_page_config(page_title="Engine Condition Prediction")

@st.cache_resource
def load_model():
    model_path = hf_hub_download(
        repo_id="ShanRaja/engine-fault-xgboost",
        filename="best_model.joblib"
    )
    return joblib.load(model_path)

model = load_model()

st.title("Engine Condition Prediction")

# Single row prediction

engine_rpm = st.number_input(
    "Engine RPM",
    min_value=50,
    max_value=2250,
    value=791,
    step=50
)

lub_oil_pressure = st.number_input(
    "Lub Oil Pressure (bar)",
    min_value=0.0,
    max_value=8.0,
    value=3.3,
    step=0.1,
    format="%.3f"
)

fuel_pressure = st.number_input(
    "Fuel Pressure (bar)",
    min_value=0.0,
    max_value=22.0,
    value=6.66,
    step=0.1,
    format="%.3f"
)

coolant_pressure = st.number_input(
    "Coolant Pressure (bar)",
    min_value=0.0,
    max_value=8.0,
    value=2.33,
    step=0.1,
    format="%.3f"
)

lub_oil_temp = st.number_input(
    "Lub Oil Temp (°C)",
    min_value=70.0,
    max_value=90.0,
    value=77.6,
    step=0.5,
    format="%.2f"
)

coolant_temp = st.number_input(
    "Coolant Temp (°C)",
    min_value=60.0,
    max_value=200.0,
    value=78.4,
    step=0.5,
    format="%.2f"
)


if st.button("Predict"):
    input_df = pd.DataFrame(
        [[
            int(engine_rpm),
            lub_oil_pressure,
            fuel_pressure,
            coolant_pressure,
            lub_oil_temp,
            coolant_temp
        ]],
        columns=[
            "Engine rpm",
            "Lub oil pressure",
            "Fuel pressure",
            "Coolant pressure",
            "lub oil temp",
            "Coolant temp"
        ]
    )

    prediction = model.predict(input_df)[0]

    label = "FAULTY" if prediction == 1 else "NORMAL"

    st.success(f"Engine Condition: {label}")


# Batch prediction
st.header("Batch Prediction from CSV")
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type="csv")

if uploaded_file is not None:
    input_data = pd.read_csv(uploaded_file)
    required_cols = ["Engine rpm","Lub oil pressure","Fuel pressure","Coolant pressure","lub oil temp","Coolant temp"]

    if not all(col in input_data.columns for col in required_cols):
        st.error(f"CSV must contain columns: {', '.join(required_cols)}")
    else:
        predictions = model.predict(input_data)
        input_data["Engine Condition"] = ["FAULTY" if p == 1 else "NORMAL" for p in predictions]
        st.success("Predictions completed!")
        st.dataframe(input_data)

        csv = input_data.to_csv(index=False).encode("utf-8")
        st.download_button(
            label="Download Predictions as CSV",
            data=csv,
            file_name="engine_predictions.csv",
            mime="text/csv",
        )