Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +45 -0
- requirements.txt +7 -3
- streamlit_app.py +45 -0
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 |
+
COPY streamlit_app.py ./app.py
|
| 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,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="sasipriyank/predectivemodel", filename="best_predective_model.joblib")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Streamlit UI for Customer Churn Prediction
|
| 13 |
+
st.title("Predective Maintainencen App")
|
| 14 |
+
st.write("The Predective Maintainencen App is an internal tool for customer that predicts whether Machine sensor is failed or not.")
|
| 15 |
+
st.write("Kindly enter the customer details to check whether they are likely to purchase or not.")
|
| 16 |
+
|
| 17 |
+
# Collect user input
|
| 18 |
+
|
| 19 |
+
LuboilPressure = st.number_input("Lub oil pressure",min_value=0.0, value=2.493592)
|
| 20 |
+
EngineRpm = st.number_input("Engine rpm", min_value=0, value=700)
|
| 21 |
+
FuelPressure= st.number_input("Fuel pressure",min_value=0.0, value=11.790927)
|
| 22 |
+
CoolantPressure = st.number_input("Coolant pressure", min_value=0.0, value=3.178981)
|
| 23 |
+
LuboilTemp = st.number_input("lub oil temp", min_value=0, value=84.144163)
|
| 24 |
+
CoolantTemp = st.number_input("Coolant temp", min_value=0, value=81.632187)
|
| 25 |
+
|
| 26 |
+
# Convert categorical inputs to match model training
|
| 27 |
+
input_data = pd.DataFrame([{
|
| 28 |
+
'Lub oil pressure': LuboilPressure,
|
| 29 |
+
'Engine rpm': EngineRpm,
|
| 30 |
+
'Fuel pressure': FuelPressure,
|
| 31 |
+
'Coolant pressure': CoolantPressure,
|
| 32 |
+
'lub oil temp': LuboilTemp,
|
| 33 |
+
'Coolant temp': CoolantTemp
|
| 34 |
+
|
| 35 |
+
}])
|
| 36 |
+
|
| 37 |
+
# Set the classification threshold
|
| 38 |
+
classification_threshold = 0.45
|
| 39 |
+
|
| 40 |
+
# Predict button
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 43 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 44 |
+
result = "Failed" if prediction == 1 else "NotFailed"
|
| 45 |
+
st.write(f"Based on the information provided, the sensor is {result} ")
|
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
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="sasipriyank/predectivemodel", filename="best_predective_model.joblib")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Streamlit UI for Customer Churn Prediction
|
| 13 |
+
st.title("Predective Maintainencen App")
|
| 14 |
+
st.write("The Predective Maintainencen App is an internal tool for customer that predicts whether Machine sensor is failed or not.")
|
| 15 |
+
st.write("Kindly enter the customer details to check whether they are likely to purchase or not.")
|
| 16 |
+
|
| 17 |
+
# Collect user input
|
| 18 |
+
|
| 19 |
+
LuboilPressure = st.number_input("Lub oil pressure",min_value=0.0, value=2.493592)
|
| 20 |
+
EngineRpm = st.number_input("Engine rpm", min_value=0, value=700)
|
| 21 |
+
FuelPressure= st.number_input("Fuel pressure",min_value=0.0, value=11.790927)
|
| 22 |
+
CoolantPressure = st.number_input("Coolant pressure", min_value=0.0, value=3.178981)
|
| 23 |
+
LuboilTemp = st.number_input("lub oil temp", min_value=0, value=84.144163)
|
| 24 |
+
CoolantTemp = st.number_input("Coolant temp", min_value=0, value=81.632187)
|
| 25 |
+
|
| 26 |
+
# Convert categorical inputs to match model training
|
| 27 |
+
input_data = pd.DataFrame([{
|
| 28 |
+
'Lub oil pressure': LuboilPressure,
|
| 29 |
+
'Engine rpm': EngineRpm,
|
| 30 |
+
'Fuel pressure': FuelPressure,
|
| 31 |
+
'Coolant pressure': CoolantPressure,
|
| 32 |
+
'lub oil temp': LuboilTemp,
|
| 33 |
+
'Coolant temp': CoolantTemp
|
| 34 |
+
|
| 35 |
+
}])
|
| 36 |
+
|
| 37 |
+
# Set the classification threshold
|
| 38 |
+
classification_threshold = 0.45
|
| 39 |
+
|
| 40 |
+
# Predict button
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 43 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 44 |
+
result = "Failed" if prediction == 1 else "NotFailed"
|
| 45 |
+
st.write(f"Based on the information provided, the sensor is {result} ")
|