Nra commited on
Commit
ef25b61
·
verified ·
1 Parent(s): 8ab5fb4

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +24 -0
  2. README.md +12 -0
  3. app.py +45 -0
  4. config.py +5 -0
  5. requirements.txt +8 -0
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # (nra_upd_02)
2
+ # Use a minimal base image with Python 3.9 installed
3
+ FROM python:3.9
4
+
5
+ # Set the working directory inside the container to /app
6
+ WORKDIR /app
7
+
8
+ # Copy all files from the current directory on the host to the container's /app directory
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 . $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.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Machine-Failure-Prediction
3
+ emoji: 🚀
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: docker
7
+ app_port: 8501
8
+ tags:
9
+ - streamlit
10
+ pinned: false
11
+ short_description: Streamlit template space
12
+ ---
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # (nra_upd_02)
2
+ import streamlit as st
3
+ import pandas as pd
4
+ from huggingface_hub import hf_hub_download
5
+ import joblib
6
+ from config import HF_REPO_ID #this doesnt work and the reference is not found on HF run
7
+
8
+
9
+ # HF_REPO_ID = "Nra/Machine-Failure-Prediction" # name is case sensitive
10
+
11
+ # Download and load the model
12
+ model_path = hf_hub_download(repo_id=HF_REPO_ID, filename="best_machine_failure_model_v1.joblib") # repo_id is case-sensitive
13
+ model = joblib.load(model_path)
14
+
15
+ # Streamlit UI for Machine Failure Prediction
16
+ st.title("Machine Failure Prediction App")
17
+ st.write("""
18
+ This application predicts the likelihood of a machine failing based on its operational parameters.
19
+ Please enter the sensor and configuration data below to get a prediction.
20
+ """)
21
+
22
+ # User input
23
+ Type = st.selectbox("Machine Type", ["H", "L", "M"])
24
+ air_temp = st.number_input("Air Temperature (K)", min_value=250.0, max_value=400.0, value=298.0, step=0.1)
25
+ process_temp = st.number_input("Process Temperature (K)", min_value=250.0, max_value=500.0, value=324.0, step=0.1)
26
+ rot_speed = st.number_input("Rotational Speed (RPM)", min_value=0, max_value=3000, value=1400)
27
+ torque = st.number_input("Torque (Nm)", min_value=0.0, max_value=100.0, value=40.0, step=0.1)
28
+ tool_wear = st.number_input("Tool Wear (min)", min_value=0, max_value=300, value=10)
29
+
30
+ # Assemble input into DataFrame
31
+ input_data = pd.DataFrame([{
32
+ 'Air temperature': air_temp,
33
+ 'Process temperature': process_temp,
34
+ 'Rotational speed': rot_speed,
35
+ 'Torque': torque,
36
+ 'Tool wear': tool_wear,
37
+ 'Type': Type
38
+ }])
39
+
40
+
41
+ if st.button("Predict Failure"):
42
+ prediction = model.predict(input_data)[0]
43
+ result = "Machine Failure" if prediction == 1 else "No Failure"
44
+ st.subheader("Prediction Result:")
45
+ st.success(f"The model predicts: **{result}**")
config.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # (nra_upd_02)
2
+ # Common configurations and constants. this has to be created separately
3
+ # as the week_3_mls folder doesn not exist at HF
4
+
5
+ HF_REPO_ID = "Nra/Machine-Failure-Prediction" # name is case sensitive
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # (nra_upd_02)
2
+ pandas==2.2.2
3
+ huggingface_hub==0.32.6
4
+ streamlit==1.43.2
5
+ joblib==1.5.1
6
+ scikit-learn==1.6.0
7
+ xgboost==2.1.4
8
+ mlflow==3.0.1