Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -43,6 +43,57 @@ st.info("Enter the current readings from the engine sensors below:")
|
|
| 43 |
# Creating columns for a cleaner layout
|
| 44 |
col1, col2 = st.columns(2)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with col1:
|
| 47 |
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=10000, value=700, step=10)
|
| 48 |
lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=20.0, value=2.5, format="%.4f")
|
|
@@ -53,6 +104,9 @@ with col2:
|
|
| 53 |
lub_oil_temp = st.number_input("Lub Oil Temp (°C)", min_value=0.0, max_value=200.0, value=84.1, format="%.4f")
|
| 54 |
coolant_temp = st.number_input("Coolant Temp (°C)", min_value=0.0, max_value=200.0, value=81.6, format="%.4f")
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
# ==========================================
|
| 57 |
# 3. Prediction Logic
|
| 58 |
# ==========================================
|
|
@@ -65,7 +119,9 @@ if st.button("Predict Engine Condition", type="primary"):
|
|
| 65 |
'Fuel pressure': fuel_pressure,
|
| 66 |
'Coolant pressure': coolant_pressure,
|
| 67 |
'lub oil temp': lub_oil_temp,
|
| 68 |
-
'Coolant temp': coolant_temp
|
|
|
|
|
|
|
| 69 |
}])
|
| 70 |
|
| 71 |
# Perform prediction
|
|
@@ -90,6 +146,37 @@ if st.button("Predict Engine Condition", type="primary"):
|
|
| 90 |
else:
|
| 91 |
st.warning("Model is not loaded. Please check your Hugging Face credentials and Repo ID.")
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
# ==========================================
|
| 94 |
# 4. Footer
|
| 95 |
# ==========================================
|
|
|
|
| 43 |
# Creating columns for a cleaner layout
|
| 44 |
col1, col2 = st.columns(2)
|
| 45 |
|
| 46 |
+
with col1:
|
| 47 |
+
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=10000, value=700, step=10)
|
| 48 |
+
lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=20.0, value=2.5, format="%.4f")
|
| 49 |
+
fuel_pressure = st.number_input("Fuel Pressure (bar)", min_value=0.0, max_value=50.0, value=11.8, format="%.4f")
|
| 50 |
+
|
| 51 |
+
%%writefile predictive_maintenance_project/deployment/app.py
|
| 52 |
+
import streamlit as st
|
| 53 |
+
import pandas as pd
|
| 54 |
+
import joblib
|
| 55 |
+
import os
|
| 56 |
+
from huggingface_hub import hf_hub_download
|
| 57 |
+
|
| 58 |
+
# ==========================================
|
| 59 |
+
# 1. Page Configuration & Model Loading
|
| 60 |
+
# ==========================================
|
| 61 |
+
st.set_page_config(page_title="Engine Predictive Maintenance", layout="centered")
|
| 62 |
+
|
| 63 |
+
# Configuration from previous training steps
|
| 64 |
+
REPO_ID = "dpanchali/predictive_maintenance_model"
|
| 65 |
+
FILENAME = "predictive_maintenance_model.joblib"
|
| 66 |
+
|
| 67 |
+
@st.cache_resource
|
| 68 |
+
def load_model():
|
| 69 |
+
"""Download and load the model from Hugging Face Hub."""
|
| 70 |
+
try:
|
| 71 |
+
# Download the model file from the repository
|
| 72 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 73 |
+
model = joblib.load(model_path)
|
| 74 |
+
return model
|
| 75 |
+
except Exception as e:
|
| 76 |
+
st.error(f"Error loading model from Hugging Face: {e}")
|
| 77 |
+
return None
|
| 78 |
+
|
| 79 |
+
# Load the model
|
| 80 |
+
model = load_model()
|
| 81 |
+
|
| 82 |
+
# ==========================================
|
| 83 |
+
# 2. UI Layout
|
| 84 |
+
# ==========================================
|
| 85 |
+
st.title("Engine Condition Predictor")
|
| 86 |
+
st.markdown("""
|
| 87 |
+
This application uses a trained **XGBoost** model to predict the health of an engine
|
| 88 |
+
based on real-time sensor data.
|
| 89 |
+
""")
|
| 90 |
+
|
| 91 |
+
st.header("Input Engine Sensor Data")
|
| 92 |
+
st.info("Enter the current readings from the engine sensors below:")
|
| 93 |
+
|
| 94 |
+
# Creating columns for a cleaner layout
|
| 95 |
+
col1, col2 = st.columns(2)
|
| 96 |
+
|
| 97 |
with col1:
|
| 98 |
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=10000, value=700, step=10)
|
| 99 |
lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=20.0, value=2.5, format="%.4f")
|
|
|
|
| 104 |
lub_oil_temp = st.number_input("Lub Oil Temp (°C)", min_value=0.0, max_value=200.0, value=84.1, format="%.4f")
|
| 105 |
coolant_temp = st.number_input("Coolant Temp (°C)", min_value=0.0, max_value=200.0, value=81.6, format="%.4f")
|
| 106 |
|
| 107 |
+
load_index = engine_rpm * fuel_pressure / 100
|
| 108 |
+
thermal_stress = coolant_temp - lub_oil_temp
|
| 109 |
+
|
| 110 |
# ==========================================
|
| 111 |
# 3. Prediction Logic
|
| 112 |
# ==========================================
|
|
|
|
| 119 |
'Fuel pressure': fuel_pressure,
|
| 120 |
'Coolant pressure': coolant_pressure,
|
| 121 |
'lub oil temp': lub_oil_temp,
|
| 122 |
+
'Coolant temp': coolant_temp,
|
| 123 |
+
'load_index' : load_index,
|
| 124 |
+
'thermal_stress' : thermal_stress
|
| 125 |
}])
|
| 126 |
|
| 127 |
# Perform prediction
|
|
|
|
| 146 |
else:
|
| 147 |
st.warning("Model is not loaded. Please check your Hugging Face credentials and Repo ID.")
|
| 148 |
|
| 149 |
+
# ==========================================
|
| 150 |
+
# 4. Footer
|
| 151 |
+
# ==========================================
|
| 152 |
+
st.sidebar.markdown("### Model Information")
|
| 153 |
+
st.sidebar.text(f"Repo: {REPO_ID}")
|
| 154 |
+
st.sidebar.text(f"File: {FILENAME}")
|
| 155 |
+
st.sidebar.markdown("---")
|
| 156 |
+
st.sidebar.write("This tool is intended for predictive maintenance scheduling based on sensor patterns.")
|
| 157 |
+
|
| 158 |
+
# Perform prediction
|
| 159 |
+
prediction = model.predict(input_data)[0]
|
| 160 |
+
prediction_proba = model.predict_proba(input_data)[0]
|
| 161 |
+
|
| 162 |
+
# Display results
|
| 163 |
+
st.divider()
|
| 164 |
+
st.subheader("Results")
|
| 165 |
+
|
| 166 |
+
if prediction == 1:
|
| 167 |
+
st.success("**Prediction: Engine is in Good Condition**")
|
| 168 |
+
else:
|
| 169 |
+
st.error("**Prediction: Maintenance Required (Potential Fault Detected)**")
|
| 170 |
+
|
| 171 |
+
# Display confidence scores
|
| 172 |
+
st.write(f"**Confidence Score:** {max(prediction_proba)*100:.2f}%")
|
| 173 |
+
|
| 174 |
+
# Optional: Display gauge or progress bar for health
|
| 175 |
+
health_score = prediction_proba[1] # Probability of class 1 (Good)
|
| 176 |
+
st.progress(health_score)
|
| 177 |
+
else:
|
| 178 |
+
st.warning("Model is not loaded. Please check your Hugging Face credentials and Repo ID.")
|
| 179 |
+
|
| 180 |
# ==========================================
|
| 181 |
# 4. Footer
|
| 182 |
# ==========================================
|