Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -11
- app.py +63 -0
- requirements.txt +6 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,25 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
build-essential \
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
COPY
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 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 |
|
| 9 |
+
COPY . .
|
|
|
|
| 10 |
|
| 11 |
+
# Install python dependencies listed in requirements.txt
|
| 12 |
RUN pip3 install -r requirements.txt
|
| 13 |
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
USER user
|
| 16 |
+
ENV HOME=/home/user\
|
| 17 |
+
PATH=/home/user/.local/bin:$PATH
|
| 18 |
|
| 19 |
+
WORKDIR $HOME/app
|
| 20 |
+
|
| 21 |
+
COPY --chown=user:user . $HOME/app
|
| 22 |
+
|
| 23 |
+
#Define the command to run the streamlit app on port "8501" and make it accessible externally
|
| 24 |
+
CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 25 |
|
|
|
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Load Model
|
| 9 |
+
# -------------------------------
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def load_model():
|
| 12 |
+
try:
|
| 13 |
+
# Download model from Hugging Face
|
| 14 |
+
model_path = hf_hub_download(
|
| 15 |
+
repo_id="Satyanjay/engine-condition-monitoring-model",
|
| 16 |
+
filename="best_model.joblib"
|
| 17 |
+
)
|
| 18 |
+
except:
|
| 19 |
+
# fallback if running locally
|
| 20 |
+
model_path = "best_model.joblib"
|
| 21 |
+
|
| 22 |
+
model = joblib.load(model_path)
|
| 23 |
+
return model
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
model = load_model()
|
| 27 |
+
|
| 28 |
+
# -------------------------------
|
| 29 |
+
# UI
|
| 30 |
+
# -------------------------------
|
| 31 |
+
st.set_page_config(page_title="Engine Condition Monitoring", layout="centered")
|
| 32 |
+
|
| 33 |
+
st.title("🚗 Engine Condition Monitoring System")
|
| 34 |
+
st.write("Enter engine parameters below to predict condition.")
|
| 35 |
+
|
| 36 |
+
# Input fields
|
| 37 |
+
engine_rpm = st.number_input("Engine RPM", min_value=0.0)
|
| 38 |
+
lub_oil_pressure = st.number_input("Lub Oil Pressure", min_value=0.0)
|
| 39 |
+
fuel_pressure = st.number_input("Fuel Pressure", min_value=0.0)
|
| 40 |
+
coolant_pressure = st.number_input("Coolant Pressure", min_value=0.0)
|
| 41 |
+
lub_oil_temp = st.number_input("Lub Oil Temperature", min_value=0.0)
|
| 42 |
+
coolant_temp = st.number_input("Coolant Temperature", min_value=0.0)
|
| 43 |
+
|
| 44 |
+
# -------------------------------
|
| 45 |
+
# Prediction
|
| 46 |
+
# -------------------------------
|
| 47 |
+
if st.button("Predict"):
|
| 48 |
+
|
| 49 |
+
input_data = pd.DataFrame([{
|
| 50 |
+
'Engine rpm': engine_rpm,
|
| 51 |
+
'Lub oil pressure': lub_oil_pressure,
|
| 52 |
+
'Fuel pressure': fuel_pressure,
|
| 53 |
+
'Coolant pressure': coolant_pressure,
|
| 54 |
+
'Lub oil temp': lub_oil_temp,
|
| 55 |
+
'Coolant temp': coolant_temp
|
| 56 |
+
}])
|
| 57 |
+
|
| 58 |
+
prediction = model.predict(input_data)[0]
|
| 59 |
+
|
| 60 |
+
if prediction == 1:
|
| 61 |
+
st.error("⚠️ Engine Condition: FAULT DETECTED")
|
| 62 |
+
else:
|
| 63 |
+
st.success("✅ Engine Condition: NORMAL")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
huggingface_hub==0.32.6
|
| 3 |
+
streamlit==1.40.0
|
| 4 |
+
joblib==1.5.1
|
| 5 |
+
scikit-learn==1.6.0
|
| 6 |
+
xgboost==2.1.4
|