File size: 1,722 Bytes
8f54a04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

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

HF_USERNAME = "Vbhadiar"
MODEL_ID = f"{HF_USERNAME}/engine-failure-classifier"

@st.cache_resource
def load_model():
    model_path = hf_hub_download(
        repo_id=MODEL_ID,
        filename="best_model.pkl",
        repo_type="model"
    )
    return joblib.load(model_path)

model = load_model()

st.title("🔧 Engine Predictive Maintenance")
st.markdown("Predict whether an engine requires maintenance based on sensor readings.")

col1, col2 = st.columns(2)

with col1:
    engine_rpm = st.number_input("Engine RPM", 0, 3000, 800)
    lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", 0.0, 10.0, 3.5, 0.1)
    fuel_pressure = st.number_input("Fuel Pressure (bar)", 0.0, 25.0, 7.0, 0.1)

with col2:
    coolant_pressure = st.number_input("Coolant Pressure (bar)", 0.0, 10.0, 2.5, 0.1)
    lub_oil_temp = st.number_input("Lub Oil Temp (°C)", 50.0, 120.0, 78.0, 0.5)
    coolant_temp = st.number_input("Coolant Temp (°C)", 50.0, 200.0, 80.0, 0.5)

if st.button("Predict"):
    df_input = 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],
    })
    pred = model.predict(df_input)[0]
    prob = model.predict_proba(df_input)[0][1]

    if pred == 1:
        st.error(f"⚠️ Maintenance required (failure probability: {prob*100:.1f}%)")
    else:
        st.success(f"✅ Engine normal (failure probability: {prob*100:.1f}% ")

    st.write("Input data:")
    st.dataframe(df_input)