Spaces:
Sleeping
Sleeping
File size: 3,530 Bytes
092959d b2b9a52 092959d b2b9a52 092959d d9d9d14 b2b9a52 092959d bf4444c b2b9a52 bf4444c b2b9a52 092959d bf4444c b2b9a52 f08df0b b2b9a52 d9d9d14 b2b9a52 d9d9d14 b2b9a52 092959d 8d8e2da 092959d bf4444c f08df0b b2b9a52 bf4444c b2b9a52 d9d9d14 bf4444c b2b9a52 bf4444c b2b9a52 bf4444c b2b9a52 |
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 |
import streamlit as st
import pandas as pd
import joblib
import os
from huggingface_hub import hf_hub_download
# ==========================================
# 1. Page Configuration & Model Loading
# ==========================================
st.set_page_config(page_title="Engine Predictive Maintenance", layout="centered")
REPO_ID = "dpanchali/predictive_maintenance_model"
FILENAME = "predictive_maintenance_model.joblib"
@st.cache_resource
def load_model():
"""Download and load the model from Hugging Face Hub."""
try:
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
model = joblib.load(model_path)
return model
except Exception as e:
st.error(f"Error loading model: {e}")
return None
model = load_model()
# ==========================================
# 2. UI Layout
# ==========================================
st.title("🚢 Engine Condition Predictor")
st.markdown("""
This application uses a trained **XGBoost** model to predict engine health
based on sensor patterns.
""")
st.header("Input Engine Sensor Data")
col1, col2 = st.columns(2)
with col1:
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=10000, value=700)
lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", min_value=0.0, value=2.5, format="%.4f")
fuel_pressure = st.number_input("Fuel Pressure (bar)", min_value=0.0, value=11.8, format="%.4f")
with col2:
coolant_pressure = st.number_input("Coolant Pressure (bar)", min_value=0.0, value=3.2, format="%.4f")
lub_oil_temp = st.number_input("Lub Oil Temp (°C)", min_value=0.0, value=84.1, format="%.4f")
coolant_temp = st.number_input("Coolant Temp (°C)", min_value=0.0, value=81.6, format="%.4f")
# ==========================================
# 3. Prediction Logic
# ==========================================
if st.button("Predict Engine Condition", type="primary"):
if model is not None:
# Calculate engineered features right before prediction
load_index = float(engine_rpm * fuel_pressure / 100)
thermal_stress = float(coolant_temp - lub_oil_temp)
# Create DataFrame with EXACT column names and order
input_data = pd.DataFrame([[
engine_rpm,
lub_oil_pressure,
fuel_pressure,
coolant_pressure,
lub_oil_temp,
coolant_temp,
load_index,
thermal_stress
]], columns=[
'Engine rpm', 'Lub oil pressure', 'Fuel pressure', 'Coolant pressure',
'lub oil temp', 'Coolant temp', 'load_index', 'thermal_stress'
])
# Perform prediction (Binary Result Only)
prediction = model.predict(input_data)[0]
st.divider()
st.subheader("Results")
# Visual Feedback based on Prediction
if prediction == 0: # Assuming 0 is Good
st.success("**Status: Engine is in Good Condition**")
else:
st.error("**Status: Maintenance Required (Potential Fault)**")
else:
st.error("Model could not be loaded. Check your Hugging Face Repo ID.")
# ==========================================
# 4. Sidebar Information
# ==========================================
with st.sidebar:
st.markdown("### Model Details")
st.text(f"Repo: {REPO_ID}")
st.markdown("---")
st.write("Calculated Features:")
st.caption(f"Load Index: {engine_rpm * fuel_pressure / 100:.2f}")
st.caption(f"Thermal Stress: {coolant_temp - lub_oil_temp:.2f}")
|