Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +100 -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,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import os
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
# ==========================================
|
| 8 |
+
# 1. Page Configuration & Model Loading
|
| 9 |
+
# ==========================================
|
| 10 |
+
st.set_page_config(page_title="Engine Predictive Maintenance", layout="centered")
|
| 11 |
+
|
| 12 |
+
# Configuration from previous training steps
|
| 13 |
+
REPO_ID = "dpanchali/predictive_maintenance_model"
|
| 14 |
+
FILENAME = "predictive_maintenance_model.joblib"
|
| 15 |
+
|
| 16 |
+
@st.cache_resource
|
| 17 |
+
def load_model():
|
| 18 |
+
"""Download and load the model from Hugging Face Hub."""
|
| 19 |
+
try:
|
| 20 |
+
# Download the model file from the repository
|
| 21 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 22 |
+
model = joblib.load(model_path)
|
| 23 |
+
return model
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.error(f"Error loading model from Hugging Face: {e}")
|
| 26 |
+
return None
|
| 27 |
+
|
| 28 |
+
# Load the model
|
| 29 |
+
model = load_model()
|
| 30 |
+
|
| 31 |
+
# ==========================================
|
| 32 |
+
# 2. UI Layout
|
| 33 |
+
# ==========================================
|
| 34 |
+
st.title("Engine Condition Predictor")
|
| 35 |
+
st.markdown("""
|
| 36 |
+
This application uses a trained **XGBoost** model to predict the health of an engine
|
| 37 |
+
based on real-time sensor data.
|
| 38 |
+
""")
|
| 39 |
+
|
| 40 |
+
st.header("Input Engine Sensor Data")
|
| 41 |
+
st.info("Enter the current readings from the engine sensors below:")
|
| 42 |
+
|
| 43 |
+
# Creating columns for a cleaner layout
|
| 44 |
+
col1, col2 = st.columns(2)
|
| 45 |
+
|
| 46 |
+
with col1:
|
| 47 |
+
engine_rpm = st.number_input("Engine RPM", min_value=0, max_value=10000, value=700, step=10)
|
| 48 |
+
lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", min_value=0.0, max_value=20.0, value=2.5, format="%.4f")
|
| 49 |
+
fuel_pressure = st.number_input("Fuel Pressure (bar)", min_value=0.0, max_value=50.0, value=11.8, format="%.4f")
|
| 50 |
+
|
| 51 |
+
with col2:
|
| 52 |
+
coolant_pressure = st.number_input("Coolant Pressure (bar)", min_value=0.0, max_value=20.0, value=3.2, format="%.4f")
|
| 53 |
+
lub_oil_temp = st.number_input("Lub Oil Temp (°C)", min_value=0.0, max_value=200.0, value=84.1, format="%.4f")
|
| 54 |
+
coolant_temp = st.number_input("Coolant Temp (°C)", min_value=0.0, max_value=200.0, value=81.6, format="%.4f")
|
| 55 |
+
|
| 56 |
+
# ==========================================
|
| 57 |
+
# 3. Prediction Logic
|
| 58 |
+
# ==========================================
|
| 59 |
+
if st.button("Predict Engine Condition", type="primary"):
|
| 60 |
+
if model is not None:
|
| 61 |
+
# Prepare input data in the same format as training
|
| 62 |
+
input_data = pd.DataFrame([{
|
| 63 |
+
'Engine rpm': engine_rpm,
|
| 64 |
+
'Lub oil pressure': lub_oil_pressure,
|
| 65 |
+
'Fuel pressure': fuel_pressure,
|
| 66 |
+
'Coolant pressure': coolant_pressure,
|
| 67 |
+
'lub oil temp': lub_oil_temp,
|
| 68 |
+
'Coolant temp': coolant_temp
|
| 69 |
+
}])
|
| 70 |
+
|
| 71 |
+
# Perform prediction
|
| 72 |
+
prediction = model.predict(input_data)[0]
|
| 73 |
+
prediction_proba = model.predict_proba(input_data)[0]
|
| 74 |
+
|
| 75 |
+
# Display results
|
| 76 |
+
st.divider()
|
| 77 |
+
st.subheader("Results")
|
| 78 |
+
|
| 79 |
+
if prediction == 1:
|
| 80 |
+
st.success("**Prediction: Engine is in Good Condition**")
|
| 81 |
+
else:
|
| 82 |
+
st.error("**Prediction: Maintenance Required (Potential Fault Detected)**")
|
| 83 |
+
|
| 84 |
+
# Display confidence scores
|
| 85 |
+
st.write(f"**Confidence Score:** {max(prediction_proba)*100:.2f}%")
|
| 86 |
+
|
| 87 |
+
# Optional: Display gauge or progress bar for health
|
| 88 |
+
health_score = prediction_proba[1] # Probability of class 1 (Good)
|
| 89 |
+
st.progress(health_score)
|
| 90 |
+
else:
|
| 91 |
+
st.warning("Model is not loaded. Please check your Hugging Face credentials and Repo ID.")
|
| 92 |
+
|
| 93 |
+
# ==========================================
|
| 94 |
+
# 4. Footer
|
| 95 |
+
# ==========================================
|
| 96 |
+
st.sidebar.markdown("### Model Information")
|
| 97 |
+
st.sidebar.text(f"Repo: {REPO_ID}")
|
| 98 |
+
st.sidebar.text(f"File: {FILENAME}")
|
| 99 |
+
st.sidebar.markdown("---")
|
| 100 |
+
st.sidebar.write("This tool is intended for predictive maintenance scheduling based on sensor patterns.")
|
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
|