File size: 2,007 Bytes
0aacd3d
c7419f1
 
 
0aacd3d
c7419f1
 
0aacd3d
 
4ab35d4
c7419f1
940b109
 
c7419f1
 
940b109
c7419f1
b2930a6
 
 
 
940b109
4ab35d4
b2930a6
 
10e6bb8
4ab35d4
c7419f1
4ab35d4
c7419f1
 
940b109
c7419f1
0aacd3d
c7419f1
 
 
 
 
4ab35d4
 
 
 
 
 
c7419f1
 
 
 
 
 
 
 
 
 
 
 
4ab35d4
 
 
1d1cf5c
4ab35d4
 
10e6bb8
4ab35d4
 
 
 
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

import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import snapshot_download, login
import os

# --- Model Config ---
model_repo_id_app = "rakesh1248/random_forest_engine_condition_classifier" # Dynamically injected from the deployment script
model_filename = "random_forest_model.joblib"

model_dir_app = "./model_cache"
os.makedirs(model_dir_app, exist_ok=True)

@st.cache_resource
def load_model_app():
    try:
        repo_path = snapshot_download(
            repo_id=model_repo_id_app,
            local_dir=model_dir_app
        )

        model_path = os.path.join(repo_path, model_filename)

        model = joblib.load(model_path)
        return model

    except Exception as e:
        st.error(f"Error loading model: {e}")
        st.stop()

loaded_model_app = load_model_app()

# --- UI ---
st.set_page_config(layout="wide")
st.title("Engine Predictive Maintenance App")

st.sidebar.header("Engine Sensor Readings")

engine_rpm = st.sidebar.slider("Engine RPM", 60, 2300, 750)
lub_oil_pressure = st.sidebar.slider("Lub Oil Pressure", 0.0, 8.0, 3.5, 0.1)
fuel_pressure = st.sidebar.slider("Fuel Pressure", 0.0, 22.0, 6.0, 0.1)
coolant_pressure = st.sidebar.slider("Coolant Pressure", 0.0, 8.0, 2.0, 0.1)
lub_oil_temp = st.sidebar.slider("Lub Oil Temperature", 70.0, 90.0, 78.0, 0.1)
coolant_temp = st.sidebar.slider("Coolant Temperature", 60.0, 200.0, 80.0, 0.1)

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
}])

st.write(input_data)

if st.button("Predict"):
    prediction = loaded_model_app.predict(input_data)
    proba = loaded_model_app.predict_proba(input_data)

    if prediction[0] == 1:
        st.error("Faulty Engine")
    else:
        st.success("Normal Engine")

    st.write(f"Normal: {proba[0][0]:.2f}")
    st.write(f"Faulty: {proba[0][1]:.2f}")