Predictive-Maintenance / streamlit_app.py
Vignesh-vigu's picture
Rename app.py to streamlit_app.py for Streamlit loading
f72601d verified
import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
# Hugging Face Model Repo
MODEL_REPO = "Vignesh-vigu/PM-XGBoost-Model"
MODEL_FILE = "best_xgb_model.joblib"
# Download and Load Model
@st.cache_resource
def load_model():
model_path = hf_hub_download(
repo_id=MODEL_REPO,
filename=MODEL_FILE,
repo_type="model"
)
return joblib.load(model_path)
model = load_model()
# Page Config
st.set_page_config(page_title="Engine Predictive Maintenance",
page_icon="βš™οΈ", layout="wide")
st.title("πŸš— Engine Predictive Maintenance System")
st.write("Predict whether an engine requires maintenance using sensor data.")
# Sidebar Inputs
st.sidebar.header("πŸ“ Engine Sensor Inputs")
rpm = st.sidebar.number_input("Engine RPM", min_value=0, max_value=4000, value=750)
oil_pressure = st.sidebar.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=15.0, value=3.0)
fuel_pressure = st.sidebar.number_input("Fuel Pressure (bar)", min_value=0.0, max_value=30.0, value=5.0)
coolant_pressure = st.sidebar.number_input("Coolant Pressure (bar)", min_value=0.0, max_value=20.0, value=2.0)
oil_temp = st.sidebar.number_input("Lub Oil Temperature (Β°C)", min_value=0.0, max_value=200.0, value=75.0)
cool_temp = st.sidebar.number_input("Coolant Temperature (Β°C)", min_value=0.0, max_value=250.0, value=80.0)
if st.sidebar.button("πŸ” Predict Engine Condition"):
input_df = pd.DataFrame([[
rpm, oil_pressure, fuel_pressure,
coolant_pressure, oil_temp, cool_temp
]], columns=[
"Engine rpm", "Lub oil pressure", "Fuel pressure",
"Coolant pressure", "lub oil temp", "Coolant temp"
])
prediction = model.predict(input_df)[0]
status = ("⚠️ Faulty Engine β€” Maintenance Required!"
if prediction == 1
else "βœ… Normal Engine β€” No Action Required")
st.subheader("🧾 Prediction Result:")
st.markdown(f"### {status}")
st.write("### πŸ” Input Data")
st.dataframe(input_df, use_container_width=True)