Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +49 -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,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Download the model from the Model Hub
|
| 7 |
+
model_path = hf_hub_download(repo_id="csankaran3/engine-condition-prediction", filename="best_engine_condition_prediction_model_v1.joblib")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Streamlit UI for Customer Churn Prediction
|
| 13 |
+
st.set_page_config(page_title="Predictive Maintenance", layout="centered")
|
| 14 |
+
st.title("Predictive Maintenance - Engine fault prediction application")
|
| 15 |
+
st.write("This App is an internal tool for automobie companies to predict engine condition (Active / Faulty) based on the sensor values.")
|
| 16 |
+
st.subheader("Kindly enter the sensor details to check whether engine condition is active or faulty.")
|
| 17 |
+
|
| 18 |
+
# Setting the minimum value and distplay value - Used min and average from the dataset for displaying values
|
| 19 |
+
engine_rpm = st.number_input("Engine RPM", min_value=61.0, value=1150.0, step=10.0)
|
| 20 |
+
lub_oil_pressure = st.number_input("Lub Oil Pressure (kPa)", min_value=0.0, value=3.63, step=0.01)
|
| 21 |
+
fuel_pressure = st.number_input("Fuel Pressure (kPa)", min_value=0.0, value=10.57, step=0.01)
|
| 22 |
+
coolant_pressure = st.number_input("Coolant Pressure (kPa)", min_value=0.0, value=7.48, step=0.01)
|
| 23 |
+
lub_oil_temp = st.number_input("Lub Oil Temperature (°C)", min_value=71.32, value=89.58, step=0.01)
|
| 24 |
+
coolant_temp = st.number_input("Coolant Temperature (°C)", min_value=61.67, value=128.60, step=0.01)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Convert inputs to match model training
|
| 28 |
+
input_data = pd.DataFrame([{
|
| 29 |
+
'Engine rpm': engine_rpm,
|
| 30 |
+
'Lub oil pressure': lub_oil_pressure,
|
| 31 |
+
'Fuel pressure': fuel_pressure,
|
| 32 |
+
'Coolant pressure': coolant_pressure,
|
| 33 |
+
'lub oil temp': lub_oil_temp,
|
| 34 |
+
'Coolant temp': coolant_temp
|
| 35 |
+
}])
|
| 36 |
+
|
| 37 |
+
# Set the classification threshold
|
| 38 |
+
classification_threshold = 0.45
|
| 39 |
+
|
| 40 |
+
# Predict button
|
| 41 |
+
if st.button("Predict Engine Condition"):
|
| 42 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 43 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 44 |
+
result = "Active" if prediction == 1 else "Faulty"
|
| 45 |
+
if (result == "Active"):
|
| 46 |
+
st.success(f"Engine condition prediction completed!.. The Engine condition is {result}.")
|
| 47 |
+
else:
|
| 48 |
+
st.error(f"Engine condition prediction completed!.. The Engine condition is {result}.")
|
| 49 |
+
|
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
|