Datasets:
Automated Workflow Sync: streamlit_app.py
Browse files- deployment/streamlit_app.py +72 -0
deployment/streamlit_app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# --- Page Configuration ---
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="Predictive Maintenance App-Final",
|
| 10 |
+
page_icon="⚙️",
|
| 11 |
+
layout="centered"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
st.title("⚙️ Engine Predictive Maintenance-Final")
|
| 15 |
+
st.write("Enter the engine sensor readings to predict if maintenance is required.")
|
| 16 |
+
|
| 17 |
+
# --- Load the Model ---
|
| 18 |
+
@st.cache_resource
|
| 19 |
+
def load_model():
|
| 20 |
+
repo_id = "Sirisha335/Predictive_Maintaince_final" # Your Hugging Face dataset repo ID
|
| 21 |
+
model_filename = "models/best_random_forest_model.joblib" # Path in repo
|
| 22 |
+
|
| 23 |
+
# Ensure the Hugging Face token is set if the model is private or requires authentication
|
| 24 |
+
# In a deployed Hugging Face Space, you would set this as a Space secret.
|
| 25 |
+
# For local testing, you might set it as an environment variable or uncomment below:
|
| 26 |
+
# os.environ['HF_TOKEN'] = 'your_hugging_face_token'
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=model_filename, repo_type="dataset")
|
| 30 |
+
model = joblib.load(model_path)
|
| 31 |
+
return model
|
| 32 |
+
except Exception as e:
|
| 33 |
+
st.error(f"Error loading model: {e}")
|
| 34 |
+
st.stop()
|
| 35 |
+
|
| 36 |
+
model = load_model()
|
| 37 |
+
|
| 38 |
+
# --- Input Features ---
|
| 39 |
+
st.header("Engine Sensor Readings")
|
| 40 |
+
|
| 41 |
+
engine_rpm = st.slider("Engine RPM", min_value=0, max_value=2500, value=750, step=10)
|
| 42 |
+
lub_oil_pressure = st.slider("Lub Oil Pressure (bar)", min_value=0.0, max_value=8.0, value=3.0, step=0.1)
|
| 43 |
+
fuel_pressure = st.slider("Fuel Pressure (bar)", min_value=0.0, max_value=25.0, value=6.0, step=0.1)
|
| 44 |
+
coolant_pressure = st.slider("Coolant Pressure (bar)", min_value=0.0, max_value=8.0, value=2.0, step=0.1)
|
| 45 |
+
coolant_temp = st.slider("Coolant Temperature (°C)", min_value=60.0, max_value=130.0, value=80.0, step=0.1) # Capped at 120
|
| 46 |
+
|
| 47 |
+
# Create a DataFrame for prediction
|
| 48 |
+
input_data = pd.DataFrame([[
|
| 49 |
+
engine_rpm, lub_oil_pressure, fuel_pressure, coolant_pressure, coolant_temp
|
| 50 |
+
]], columns=[
|
| 51 |
+
'Engine rpm', 'Lub oil pressure', 'Fuel pressure', 'Coolant pressure', 'Coolant temp'
|
| 52 |
+
])
|
| 53 |
+
|
| 54 |
+
# --- Prediction ---
|
| 55 |
+
if st.button("Predict Engine Condition"): # Simplified button text
|
| 56 |
+
prediction = model.predict(input_data)[0]
|
| 57 |
+
prediction_proba = model.predict_proba(input_data)[0]
|
| 58 |
+
|
| 59 |
+
st.subheader("Prediction Result")
|
| 60 |
+
if prediction == 1:
|
| 61 |
+
st.error(f"⚠️ **Maintenance Required!** (Faulty Engine Predicted)")
|
| 62 |
+
st.write(f"Confidence (Faulty): **{prediction_proba[1]*100:.2f}%**")
|
| 63 |
+
st.write(f"Confidence (Normal): {prediction_proba[0]*100:.2f}%")
|
| 64 |
+
st.warning("Immediate inspection and maintenance are recommended.")
|
| 65 |
+
else:
|
| 66 |
+
st.success(f"✅ **Engine Condition: Normal**")
|
| 67 |
+
st.write(f"Confidence (Normal): **{prediction_proba[0]*100:.2f}%**")
|
| 68 |
+
st.write(f"Confidence (Faulty): {prediction_proba[1]*100:.2f}%")
|
| 69 |
+
st.info("Continue regular monitoring.")
|
| 70 |
+
|
| 71 |
+
st.markdown("---")
|
| 72 |
+
st.caption("This application predicts engine condition based on sensor readings using a pre-trained Random Forest Classifier.")
|