File size: 2,514 Bytes
ba4e389 38facbe ba4e389 b5d6455 ba4e389 b5d6455 ba4e389 b5d6455 ba4e389 | 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 | import os
import joblib
import pandas as pd
import streamlit as st
from huggingface_hub import hf_hub_download
# -----------------------------
# Hugging Face model details
# -----------------------------
MODEL_REPO_ID = "avatar2102/engine-predictive-maintenance-model"
MODEL_FILENAME = "adaboost_final_model.joblib"
# -----------------------------
# Streamlit page config
# -----------------------------
st.set_page_config(
page_title="Predictive Maintenance App",
layout="centered"
)
st.title("Predictive Maintenance for Engine Health")
st.markdown("Enter the engine sensor values below to predict whether the engine is healthy or requires maintenance.")
# -----------------------------
# Load model from Hugging Face
# -----------------------------
@st.cache_resource
def load_model():
model_path = hf_hub_download(
repo_id=MODEL_REPO_ID,
filename=MODEL_FILENAME,
repo_type="model"
)
model = joblib.load(model_path)
return model
model = load_model()
# -----------------------------
# User inputs
# -----------------------------
st.subheader("Enter Sensor Readings")
engine_rpm = st.number_input("Engine RPM", min_value=0.0, value=700.0, step=1.0)
lub_oil_pressure = st.number_input("Lubricating Oil Pressure", min_value=0.0, value=3.5, step=0.1)
fuel_pressure = st.number_input("Fuel Pressure", min_value=0.0, value=4.0, step=0.1)
coolant_pressure = st.number_input("Coolant Pressure", min_value=0.0, value=2.5, step=0.1)
lub_oil_temp = st.number_input("Lubricating Oil Temperature", min_value=0.0, value=75.0, step=0.1)
coolant_temp = st.number_input("Coolant Temperature", min_value=0.0, value=80.0, step=0.1)
# -----------------------------
# Prediction
# -----------------------------
if st.button("Predict Engine Condition"):
input_df = 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 = model.predict(input_df)[0]
prediction_proba = model.predict_proba(input_df)[0]
st.subheader("Prediction Result")
if prediction == 1:
st.error("Engine Requires Maintenance")
st.write(f"Confidence: {prediction_proba[1]:.2%}")
else:
st.success("Engine is Healthy")
st.write(f"Confidence: {prediction_proba[0]:.2%}")
st.subheader("Input DataFrame")
st.dataframe(input_df)
|