Upload folder using huggingface_hub
Browse files- Dockerfile +20 -12
- app.py +96 -0
- requirements.txt +10 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,28 @@
|
|
| 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 |
+
# Create a non-root user 'user' with UID 1000 and set ownership.
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
USER user
|
| 16 |
+
ENV HOME=/home/user \
|
| 17 |
+
PATH=/home/user/.local/bin:$PATH
|
| 18 |
+
|
| 19 |
+
# Change working directory to the user's application directory.
|
| 20 |
+
WORKDIR $HOME/app
|
| 21 |
|
| 22 |
+
# Copy the application files to the user's directory.
|
| 23 |
+
COPY --chown=user . $HOME/app
|
| 24 |
|
| 25 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally.
|
| 26 |
+
# --server.address=0.0.0.0 makes the app reachable from any IP address.
|
| 27 |
+
# --server.enableXsrfProtection=false disables CSRF protection, often needed for public deployments.
|
| 28 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 best engine model from Hugging Face Model Hub.
|
| 7 |
+
# The model is a scikit-learn compatible estimator saved with joblib.
|
| 8 |
+
model_path = hf_hub_download(
|
| 9 |
+
repo_id='Garg06/Predictive-Maintenance-Model',
|
| 10 |
+
filename='best_engine_model.joblib'
|
| 11 |
+
)
|
| 12 |
+
model = joblib.load(model_path)
|
| 13 |
+
|
| 14 |
+
# ββ App header ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 15 |
+
st.title('Engine Predictive Maintenance App')
|
| 16 |
+
st.write("""
|
| 17 |
+
This application predicts whether an engine is **Faulty** or **Normal** based on
|
| 18 |
+
real-time sensor readings. Enter the current sensor values below to get a prediction.
|
| 19 |
+
""")
|
| 20 |
+
|
| 21 |
+
# ββ Sensor input fields βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 22 |
+
st.header('Engine Sensor Readings')
|
| 23 |
+
|
| 24 |
+
# Engine RPM: observed range 61β2239, typical idle around 750β800 RPM.
|
| 25 |
+
engine_rpm = st.number_input(
|
| 26 |
+
'Engine RPM',
|
| 27 |
+
min_value=0.0, max_value=2500.0, value=800.0, step=1.0,
|
| 28 |
+
help='Engine revolutions per minute. Typical idle: ~750 RPM.'
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Lub oil pressure: observed range 0β7.27 bar.
|
| 32 |
+
lub_oil_pressure = st.number_input(
|
| 33 |
+
'Lub Oil Pressure (bar)',
|
| 34 |
+
min_value=0.0, max_value=10.0, value=3.3, step=0.01,
|
| 35 |
+
help='Lubrication oil pressure in bar. Healthy range: 2.5β4.5 bar.'
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Fuel pressure: observed range 0β21.14 bar.
|
| 39 |
+
fuel_pressure = st.number_input(
|
| 40 |
+
'Fuel Pressure (bar)',
|
| 41 |
+
min_value=0.0, max_value=25.0, value=6.7, step=0.01,
|
| 42 |
+
help='Fuel system pressure in bar. Healthy range: 4.9β7.7 bar.'
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Coolant pressure: observed range 0β7.48 bar.
|
| 46 |
+
coolant_pressure = st.number_input(
|
| 47 |
+
'Coolant Pressure (bar)',
|
| 48 |
+
min_value=0.0, max_value=10.0, value=2.3, step=0.01,
|
| 49 |
+
help='Engine coolant system pressure in bar. Healthy range: 1.6β2.8 bar.'
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# Lub oil temperature: observed range 71β90 Β°C.
|
| 53 |
+
lub_oil_temp = st.number_input(
|
| 54 |
+
'Lub Oil Temperature (Β°C)',
|
| 55 |
+
min_value=60.0, max_value=100.0, value=77.6, step=0.1,
|
| 56 |
+
help='Lubrication oil temperature in Β°C. Normal operating range: 75β80 Β°C.'
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Coolant temperature: observed range 62β196 Β°C.
|
| 60 |
+
coolant_temp = st.number_input(
|
| 61 |
+
'Coolant Temperature (Β°C)',
|
| 62 |
+
min_value=60.0, max_value=200.0, value=78.4, step=0.1,
|
| 63 |
+
help='Engine coolant temperature in Β°C. Normal range: 74β83 Β°C.'
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# ββ Assemble input dataframe ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 67 |
+
# Column names must exactly match those used during model training.
|
| 68 |
+
input_data = pd.DataFrame([{
|
| 69 |
+
'Engine rpm': engine_rpm,
|
| 70 |
+
'Lub oil pressure': lub_oil_pressure,
|
| 71 |
+
'Fuel pressure': fuel_pressure,
|
| 72 |
+
'Coolant pressure': coolant_pressure,
|
| 73 |
+
'lub oil temp': lub_oil_temp,
|
| 74 |
+
'Coolant temp': coolant_temp,
|
| 75 |
+
}])
|
| 76 |
+
|
| 77 |
+
# ββ Prediction ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 78 |
+
if st.button('Predict Engine Condition'):
|
| 79 |
+
prediction = model.predict(input_data)[0]
|
| 80 |
+
probability = model.predict_proba(input_data)[0]
|
| 81 |
+
|
| 82 |
+
if prediction == 1:
|
| 83 |
+
st.error(
|
| 84 |
+
f'β οΈ **Faulty Engine Detected!** '
|
| 85 |
+
f'Confidence: {probability[1]:.1%} '
|
| 86 |
+
f'\n\nImmediate inspection is recommended to prevent breakdown.'
|
| 87 |
+
)
|
| 88 |
+
else:
|
| 89 |
+
st.success(
|
| 90 |
+
f'β
**Engine is Normal.** '
|
| 91 |
+
f'Confidence: {probability[0]:.1%} '
|
| 92 |
+
f'\n\nAll sensor readings are within acceptable limits.'
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
st.subheader('Input Summary')
|
| 96 |
+
st.dataframe(input_data)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Define the Python package dependencies for the Streamlit application.
|
| 2 |
+
# These versions ensure reproducibility of the deployment environment.
|
| 3 |
+
pandas==2.2.2
|
| 4 |
+
huggingface_hub==0.32.6
|
| 5 |
+
streamlit==1.43.2
|
| 6 |
+
joblib==1.5.1
|
| 7 |
+
scikit-learn==1.6.0
|
| 8 |
+
xgboost==2.1.4
|
| 9 |
+
imbalanced-learn==0.12.4
|
| 10 |
+
mlflow==3.0.1
|