Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from model_loader import load_model
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Predictive Maintenance App")
|
| 6 |
+
|
| 7 |
+
st.title("Predictive Maintenance – Engine Fault Prediction")
|
| 8 |
+
|
| 9 |
+
st.markdown(
|
| 10 |
+
"This app uses a Gradient Boosting model to predict whether an engine is **Normal (0)** "
|
| 11 |
+
"or **Faulty (1)** based on sensor readings."
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Load model once
|
| 15 |
+
model = load_model()
|
| 16 |
+
|
| 17 |
+
# Input fields
|
| 18 |
+
st.sidebar.header("Input Engine Sensor Values")
|
| 19 |
+
|
| 20 |
+
engine_rpm = st.sidebar.number_input("Engine RPM", min_value=1, max_value=5000, value=800)
|
| 21 |
+
lub_oil_pressure = st.sidebar.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=10.0, value=3.0)
|
| 22 |
+
fuel_pressure = st.sidebar.number_input("Fuel Pressure (bar)", min_value=0.0, max_value=25.0, value=6.0)
|
| 23 |
+
coolant_pressure = st.sidebar.number_input("Coolant Pressure (bar)", min_value=0.0, max_value=10.0, value=2.0)
|
| 24 |
+
lub_oil_temp = st.sidebar.number_input("Lub Oil Temperature (°C)", min_value=0.0, max_value=150.0, value=78.0)
|
| 25 |
+
coolant_temp = st.sidebar.number_input("Coolant Temperature (°C)", min_value=0.0, max_value=200.0, value=78.0)
|
| 26 |
+
|
| 27 |
+
# Convert input to dataframe (as required by model)
|
| 28 |
+
input_df = pd.DataFrame([{
|
| 29 |
+
"Engine_RPM": engine_rpm,
|
| 30 |
+
"Lub_Oil_Pressure": lub_oil_pressure,
|
| 31 |
+
"Fuel_Pressure": fuel_pressure,
|
| 32 |
+
"Coolant_Pressure": coolant_pressure,
|
| 33 |
+
"Lub_Oil_Temperature": lub_oil_temp,
|
| 34 |
+
"Coolant_Temperature": coolant_temp
|
| 35 |
+
}])
|
| 36 |
+
|
| 37 |
+
st.subheader("Input Data")
|
| 38 |
+
st.write(input_df)
|
| 39 |
+
|
| 40 |
+
if st.button("Predict Engine Condition"):
|
| 41 |
+
expected = getattr(model, "expected_features", None)
|
| 42 |
+
|
| 43 |
+
if expected:
|
| 44 |
+
for col in expected:
|
| 45 |
+
if col not in input_df.columns:
|
| 46 |
+
input_df[col] = 0
|
| 47 |
+
input_df = input_df[expected]
|
| 48 |
+
|
| 49 |
+
pred = model.predict(input_df)[0]
|
| 50 |
+
label = "Faulty Engine (Maintenance Required)" if pred == 1 else "Normal Engine"
|
| 51 |
+
st.subheader("Prediction")
|
| 52 |
+
st.success(f"Engine Condition: {label}")
|