Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +177 -0
- requirements.txt +7 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9
|
| 3 |
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
RUN pip3 install -r requirements.txt
|
| 12 |
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
USER user
|
| 15 |
+
ENV HOME=/home/user \
|
| 16 |
+
PATH=/home/user/.local/bin:$PATH
|
| 17 |
+
|
| 18 |
+
WORKDIR $HOME/app
|
| 19 |
|
| 20 |
+
COPY --chown=user . $HOME/app
|
| 21 |
|
| 22 |
+
# Define the command to run the Streamlit app on port "8501" and make it accessible externally
|
| 23 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Download and load the model
|
| 7 |
+
model_path = hf_hub_download(repo_id="JohnsonSAimlarge/engine-failure-predictor", filename="engine_failure_model.joblib")
|
| 8 |
+
model = joblib.load(model_path)
|
| 9 |
+
|
| 10 |
+
# ------------------------------
|
| 11 |
+
# Streamlit UI
|
| 12 |
+
# ------------------------------
|
| 13 |
+
st.title("🔧 Engine Failure Prediction System")
|
| 14 |
+
st.write("""
|
| 15 |
+
This application predicts the likelihood of engine failure based on sensor readings and operational parameters.
|
| 16 |
+
Please enter **Engine Sensor Data** below to get a prediction.
|
| 17 |
+
""")
|
| 18 |
+
|
| 19 |
+
# ------------------------------
|
| 20 |
+
# User Inputs
|
| 21 |
+
# ------------------------------
|
| 22 |
+
st.subheader("Engine Operational Parameters")
|
| 23 |
+
|
| 24 |
+
col1, col2 = st.columns(2)
|
| 25 |
+
|
| 26 |
+
with col1:
|
| 27 |
+
engine_rpm = st.number_input(
|
| 28 |
+
"Engine RPM (Revolutions Per Minute)",
|
| 29 |
+
min_value=0,
|
| 30 |
+
max_value=10000,
|
| 31 |
+
value=3000,
|
| 32 |
+
help="Normal range: 500-8000 RPM"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
lub_oil_pressure = st.number_input(
|
| 36 |
+
"Lubricating Oil Pressure (bar)",
|
| 37 |
+
min_value=0.0,
|
| 38 |
+
max_value=10.0,
|
| 39 |
+
value=4.5,
|
| 40 |
+
step=0.1,
|
| 41 |
+
help="Normal range: 2.0-6.0 bar"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
fuel_pressure = st.number_input(
|
| 45 |
+
"Fuel Pressure (bar)",
|
| 46 |
+
min_value=0.0,
|
| 47 |
+
max_value=10.0,
|
| 48 |
+
value=4.0,
|
| 49 |
+
step=0.1,
|
| 50 |
+
help="Normal range: 2.0-6.0 bar"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
with col2:
|
| 54 |
+
coolant_pressure = st.number_input(
|
| 55 |
+
"Coolant Pressure (bar)",
|
| 56 |
+
min_value=0.0,
|
| 57 |
+
max_value=5.0,
|
| 58 |
+
value=2.5,
|
| 59 |
+
step=0.1,
|
| 60 |
+
help="Normal range: 1.5-3.5 bar"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
lub_oil_temp = st.number_input(
|
| 64 |
+
"Lubricating Oil Temperature (°C)",
|
| 65 |
+
min_value=0,
|
| 66 |
+
max_value=200,
|
| 67 |
+
value=75,
|
| 68 |
+
help="Normal range: 50-120°C"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
coolant_temp = st.number_input(
|
| 72 |
+
"Coolant Temperature (°C)",
|
| 73 |
+
min_value=0,
|
| 74 |
+
max_value=150,
|
| 75 |
+
value=80,
|
| 76 |
+
help="Normal range: 60-100°C"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# ------------------------------
|
| 80 |
+
# Prepare Input for Prediction
|
| 81 |
+
# ------------------------------
|
| 82 |
+
input_data = {
|
| 83 |
+
"Engine rpm": engine_rpm,
|
| 84 |
+
"Lub oil pressure": lub_oil_pressure,
|
| 85 |
+
"Fuel pressure": fuel_pressure,
|
| 86 |
+
"Coolant pressure": coolant_pressure,
|
| 87 |
+
"lub oil temp": lub_oil_temp,
|
| 88 |
+
"Coolant temp": coolant_temp
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
input_df = pd.DataFrame([input_data])
|
| 92 |
+
|
| 93 |
+
# Display input summary
|
| 94 |
+
st.subheader("Input Summary")
|
| 95 |
+
st.dataframe(input_df, use_container_width=True)
|
| 96 |
+
|
| 97 |
+
# ------------------------------
|
| 98 |
+
# Prediction
|
| 99 |
+
# ------------------------------
|
| 100 |
+
if st.button("🔍 Predict Engine Condition", type="primary"):
|
| 101 |
+
try:
|
| 102 |
+
prediction = model.predict(input_df)[0]
|
| 103 |
+
probability = model.predict_proba(input_df)[0][1]
|
| 104 |
+
|
| 105 |
+
# Use custom threshold for imbalanced dataset
|
| 106 |
+
# Adjust based on your model's optimal threshold
|
| 107 |
+
classification_threshold = 0.5
|
| 108 |
+
prediction = (probability >= classification_threshold).astype(int)
|
| 109 |
+
|
| 110 |
+
st.markdown("---")
|
| 111 |
+
st.subheader("Prediction Results")
|
| 112 |
+
|
| 113 |
+
if prediction == 1:
|
| 114 |
+
st.error(f"⚠️ **ENGINE FAILURE PREDICTED** - Immediate maintenance required!")
|
| 115 |
+
st.error(f"**Failure Probability: {probability:.2%}**")
|
| 116 |
+
st.warning("""
|
| 117 |
+
**Recommended Actions:**
|
| 118 |
+
- Stop engine operation immediately
|
| 119 |
+
- Conduct thorough inspection
|
| 120 |
+
- Check all sensor readings
|
| 121 |
+
- Consult maintenance team
|
| 122 |
+
""")
|
| 123 |
+
else:
|
| 124 |
+
st.success(f"✅ **ENGINE CONDITION NORMAL** - No immediate action required")
|
| 125 |
+
st.success(f"**Failure Probability: {probability:.2%}**")
|
| 126 |
+
st.info("""
|
| 127 |
+
**Maintenance Recommendations:**
|
| 128 |
+
- Continue regular monitoring
|
| 129 |
+
- Schedule routine maintenance as planned
|
| 130 |
+
- Keep monitoring sensor readings
|
| 131 |
+
""")
|
| 132 |
+
|
| 133 |
+
# Display confidence meter
|
| 134 |
+
st.subheader("Confidence Level")
|
| 135 |
+
confidence = max(probability, 1 - probability)
|
| 136 |
+
st.progress(confidence)
|
| 137 |
+
st.write(f"Model Confidence: {confidence:.2%}")
|
| 138 |
+
|
| 139 |
+
except Exception as e:
|
| 140 |
+
st.error(f"Error during prediction: {str(e)}")
|
| 141 |
+
st.info("Please check your input values and try again.")
|
| 142 |
+
|
| 143 |
+
# ------------------------------
|
| 144 |
+
# Additional Information
|
| 145 |
+
# ------------------------------
|
| 146 |
+
with st.expander("ℹ️ About This Model"):
|
| 147 |
+
st.write("""
|
| 148 |
+
**Model Information:**
|
| 149 |
+
- Algorithm: XGBoost with SMOTE for class balancing
|
| 150 |
+
- Test Accuracy: 64.42%
|
| 151 |
+
- Precision: 76.42%
|
| 152 |
+
- Recall: 63.01%
|
| 153 |
+
- Dataset: 19,535 engine records
|
| 154 |
+
|
| 155 |
+
**Most Important Features:**
|
| 156 |
+
1. Engine RPM (38.3%)
|
| 157 |
+
2. Fuel Pressure (16.2%)
|
| 158 |
+
3. Oil Temperature (13.7%)
|
| 159 |
+
|
| 160 |
+
**Model Repository:** [JohnsonSAimlarge/engine-failure-predictor](https://huggingface.co/JohnsonSAimlarge/engine-failure-predictor)
|
| 161 |
+
""")
|
| 162 |
+
|
| 163 |
+
with st.expander("📊 Feature Ranges & Guidelines"):
|
| 164 |
+
st.write("""
|
| 165 |
+
| Parameter | Normal Range | Critical Threshold |
|
| 166 |
+
|-----------|--------------|-------------------|
|
| 167 |
+
| Engine RPM | 500-8000 | >8000 or <500 |
|
| 168 |
+
| Lub Oil Pressure | 2.0-6.0 bar | <2.0 or >6.0 |
|
| 169 |
+
| Fuel Pressure | 2.0-6.0 bar | <2.0 or >6.0 |
|
| 170 |
+
| Coolant Pressure | 1.5-3.5 bar | <1.5 or >3.5 |
|
| 171 |
+
| Lub Oil Temp | 50-120°C | >120°C |
|
| 172 |
+
| Coolant Temp | 60-100°C | >100°C |
|
| 173 |
+
""")
|
| 174 |
+
|
| 175 |
+
# Footer
|
| 176 |
+
st.markdown("---")
|
| 177 |
+
st.caption("Engine Failure Prediction System | Powered by XGBoost & Hugging Face")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
huggingface_hub==0.32.6
|
| 3 |
+
streamlit==1.43.2
|
| 4 |
+
joblib==1.5.1
|
| 5 |
+
scikit-learn==1.6.0
|
| 6 |
+
xgboost==2.1.4
|
| 7 |
+
mlflow==3.0.1
|