geniusut commited on
Commit
1079995
·
verified ·
1 Parent(s): 4481fb1

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -12
  2. app.py +91 -0
  3. requirements.txt +7 -2
Dockerfile CHANGED
@@ -1,20 +1,28 @@
1
- FROM python:3.13.5-slim
2
 
 
 
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
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
- EXPOSE 8501
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
1
 
2
+ # Use Python base image
3
+ FROM python:3.9
4
+
5
+ # Set working directory
6
  WORKDIR /app
7
 
8
+ # Copy project files
9
+ COPY . .
10
+
11
+ # Install dependencies
12
+ RUN pip install -r requirements.txt
13
+
14
+ # Create non-root user
15
+ RUN useradd -m -u 1000 user
16
+
17
+ USER user
18
 
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
 
22
+ WORKDIR $HOME/app
23
 
24
+ COPY --chown=user . $HOME/app
25
 
26
+ # Run Streamlit application
27
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
28
 
 
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # =========================================
9
+ # Load Model from Hugging Face Hub
10
+ # =========================================
11
+
12
+ model_path = hf_hub_download(
13
+ repo_id="geniusut/engine-predictive-maintenance-model",
14
+ filename="best_model.pkl"
15
+ )
16
+
17
+ model = joblib.load(model_path)
18
+
19
+ # =========================================
20
+ # Streamlit UI
21
+ # =========================================
22
+
23
+ st.title("Engine Predictive Maintenance")
24
+
25
+ st.write(
26
+ "Enter engine operational parameters "
27
+ "to predict maintenance requirements."
28
+ )
29
+
30
+ # =========================================
31
+ # User Inputs
32
+ # =========================================
33
+
34
+ engine_rpm = st.number_input(
35
+ "Engine RPM",
36
+ value=800.0
37
+ )
38
+
39
+ lub_oil_pressure = st.number_input(
40
+ "Lub Oil Pressure",
41
+ value=3.5
42
+ )
43
+
44
+ fuel_pressure = st.number_input(
45
+ "Fuel Pressure",
46
+ value=6.5
47
+ )
48
+
49
+ coolant_pressure = st.number_input(
50
+ "Coolant Pressure",
51
+ value=2.5
52
+ )
53
+
54
+ lub_oil_temp = st.number_input(
55
+ "Lub Oil Temperature",
56
+ value=75.0
57
+ )
58
+
59
+ coolant_temp = st.number_input(
60
+ "Coolant Temperature",
61
+ value=80.0
62
+ )
63
+
64
+ # =========================================
65
+ # Prepare Input Data
66
+ # =========================================
67
+
68
+ input_data = pd.DataFrame([{
69
+ "Engine_RPM": engine_rpm,
70
+ "Lub_Oil_Pressure": lub_oil_pressure,
71
+ "Fuel_Pressure": fuel_pressure,
72
+ "Coolant_Pressure": coolant_pressure,
73
+ "Lub_Oil_Temperature": lub_oil_temp,
74
+ "Coolant_Temperature": coolant_temp
75
+ }])
76
+
77
+ # =========================================
78
+ # Predict
79
+ # =========================================
80
+
81
+ if st.button("Predict"):
82
+
83
+ prediction = model.predict(input_data)[0]
84
+
85
+ result = (
86
+ "Maintenance Required"
87
+ if prediction == 1
88
+ else "Engine Operating Normally"
89
+ )
90
+
91
+ st.success(f"Prediction Result: {result}")
requirements.txt CHANGED
@@ -1,3 +1,8 @@
1
- altair
2
  pandas
3
- streamlit
 
 
 
 
 
 
1
+
2
  pandas
3
+ streamlit
4
+ huggingface_hub
5
+ joblib
6
+ scikit-learn
7
+ xgboost
8
+ mlflow