Spaces:
Sleeping
Sleeping
Add files via upload
Browse files- Dockerfile +24 -0
- app.py +57 -0
- requirements.txt +8 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Use the official lightweight Python image
|
| 3 |
+
FROM python:3.9-slim
|
| 4 |
+
|
| 5 |
+
# Set the working directory in the container
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Install system dependencies for XGBoost/Scikit-learn
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
build-essential \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Copy the requirements file and install Python libraries
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
+
|
| 17 |
+
# Copy the rest of the application code
|
| 18 |
+
COPY . .
|
| 19 |
+
|
| 20 |
+
# Expose the port Streamlit runs on (Hugging Face default is 7860)
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Command to run the app
|
| 24 |
+
CMD ["streamlit", "run", "app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
# 1. Load the model from Hugging Face Hub
|
| 8 |
+
# Replace with your actual repo and filename if different
|
| 9 |
+
REPO_ID = "P-Mishra/engine-predictive-maintenance"
|
| 10 |
+
FILENAME = "rf_predictive_maintenance.pkl"
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 14 |
+
model = joblib.load(model_path)
|
| 15 |
+
except Exception as e:
|
| 16 |
+
st.error(f"Error loading model: {e}")
|
| 17 |
+
|
| 18 |
+
st.title("🚢 Engine Predictive Maintenance")
|
| 19 |
+
st.write("Professional Monitoring System for Engine Health")
|
| 20 |
+
|
| 21 |
+
# 2. Input Fields
|
| 22 |
+
col1, col2 = st.columns(2)
|
| 23 |
+
with col1:
|
| 24 |
+
engine_rpm = st.number_input("Engine RPM", value=1000)
|
| 25 |
+
lub_oil_temp = st.number_input("Lubricating Oil Temp", value=80.0)
|
| 26 |
+
fuel_pressure = st.number_input("Fuel Pressure", value=5.0)
|
| 27 |
+
with col2:
|
| 28 |
+
coolant_temp = st.number_input("Coolant Temp", value=75.0)
|
| 29 |
+
coolant_pressure = st.number_input("Coolant Pressure", value=3.0)
|
| 30 |
+
|
| 31 |
+
# 3. Feature Engineering (must match your notebook logic exactly)
|
| 32 |
+
eps = 1e-6
|
| 33 |
+
coolant_interaction = coolant_temp * coolant_pressure
|
| 34 |
+
coolant_ratio = coolant_temp / (coolant_pressure + eps)
|
| 35 |
+
oil_rpm_interaction = lub_oil_temp * engine_rpm
|
| 36 |
+
fuel_rpm_ratio = fuel_pressure / (engine_rpm + eps)
|
| 37 |
+
|
| 38 |
+
# 4. Prediction
|
| 39 |
+
input_df = pd.DataFrame([{
|
| 40 |
+
'engine_rpm': engine_rpm,
|
| 41 |
+
'lub_oil_temp': lub_oil_temp,
|
| 42 |
+
'fuel_pressure': fuel_pressure,
|
| 43 |
+
'coolant_temp': coolant_temp,
|
| 44 |
+
'coolant_pressure': coolant_pressure,
|
| 45 |
+
'coolant_temp_pressure_interaction': coolant_interaction,
|
| 46 |
+
'coolant_temp_pressure_ratio': coolant_ratio,
|
| 47 |
+
'lub_oil_temp_engine_rpm_interaction': oil_rpm_interaction,
|
| 48 |
+
'fuel_pressure_engine_rpm_ratio': fuel_rpm_ratio
|
| 49 |
+
}])
|
| 50 |
+
|
| 51 |
+
if st.button("Analyze Engine Condition"):
|
| 52 |
+
prediction = model.predict(input_df)
|
| 53 |
+
if prediction[0] == 1:
|
| 54 |
+
st.error("🚨 CRITICAL: Maintenance Required Immediately")
|
| 55 |
+
else:
|
| 56 |
+
st.success("✅ NORMAL: Engine operating within safe parameters")
|
| 57 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
streamlit
|
| 3 |
+
pandas
|
| 4 |
+
numpy
|
| 5 |
+
joblib
|
| 6 |
+
huggingface_hub
|
| 7 |
+
scikit-learn
|
| 8 |
+
xgboost
|