Garg06 commited on
Commit
1fbe497
Β·
verified Β·
1 Parent(s): b536ffa

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -12
  2. app.py +96 -0
  3. requirements.txt +10 -3
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
+ # 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
+ # Create a non-root user 'user' with UID 1000 and set ownership.
14
+ RUN useradd -m -u 1000 user
15
+ USER user
16
+ ENV HOME=/home/user \
17
+ PATH=/home/user/.local/bin:$PATH
18
+
19
+ # Change working directory to the user's application directory.
20
+ WORKDIR $HOME/app
21
 
22
+ # Copy the application files to the user's directory.
23
+ COPY --chown=user . $HOME/app
24
 
25
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally.
26
+ # --server.address=0.0.0.0 makes the app reachable from any IP address.
27
+ # --server.enableXsrfProtection=false disables CSRF protection, often needed for public deployments.
28
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from huggingface_hub import hf_hub_download
4
+ import joblib
5
+
6
+ # Download and load the best engine model from Hugging Face Model Hub.
7
+ # The model is a scikit-learn compatible estimator saved with joblib.
8
+ model_path = hf_hub_download(
9
+ repo_id='Garg06/Predictive-Maintenance-Model',
10
+ filename='best_engine_model.joblib'
11
+ )
12
+ model = joblib.load(model_path)
13
+
14
+ # ── App header ────────────────────────────────────────────────────────────
15
+ st.title('Engine Predictive Maintenance App')
16
+ st.write("""
17
+ This application predicts whether an engine is **Faulty** or **Normal** based on
18
+ real-time sensor readings. Enter the current sensor values below to get a prediction.
19
+ """)
20
+
21
+ # ── Sensor input fields ───────────────────────────────────────────────────
22
+ st.header('Engine Sensor Readings')
23
+
24
+ # Engine RPM: observed range 61–2239, typical idle around 750–800 RPM.
25
+ engine_rpm = st.number_input(
26
+ 'Engine RPM',
27
+ min_value=0.0, max_value=2500.0, value=800.0, step=1.0,
28
+ help='Engine revolutions per minute. Typical idle: ~750 RPM.'
29
+ )
30
+
31
+ # Lub oil pressure: observed range 0–7.27 bar.
32
+ lub_oil_pressure = st.number_input(
33
+ 'Lub Oil Pressure (bar)',
34
+ min_value=0.0, max_value=10.0, value=3.3, step=0.01,
35
+ help='Lubrication oil pressure in bar. Healthy range: 2.5–4.5 bar.'
36
+ )
37
+
38
+ # Fuel pressure: observed range 0–21.14 bar.
39
+ fuel_pressure = st.number_input(
40
+ 'Fuel Pressure (bar)',
41
+ min_value=0.0, max_value=25.0, value=6.7, step=0.01,
42
+ help='Fuel system pressure in bar. Healthy range: 4.9–7.7 bar.'
43
+ )
44
+
45
+ # Coolant pressure: observed range 0–7.48 bar.
46
+ coolant_pressure = st.number_input(
47
+ 'Coolant Pressure (bar)',
48
+ min_value=0.0, max_value=10.0, value=2.3, step=0.01,
49
+ help='Engine coolant system pressure in bar. Healthy range: 1.6–2.8 bar.'
50
+ )
51
+
52
+ # Lub oil temperature: observed range 71–90 Β°C.
53
+ lub_oil_temp = st.number_input(
54
+ 'Lub Oil Temperature (Β°C)',
55
+ min_value=60.0, max_value=100.0, value=77.6, step=0.1,
56
+ help='Lubrication oil temperature in Β°C. Normal operating range: 75–80 Β°C.'
57
+ )
58
+
59
+ # Coolant temperature: observed range 62–196 Β°C.
60
+ coolant_temp = st.number_input(
61
+ 'Coolant Temperature (Β°C)',
62
+ min_value=60.0, max_value=200.0, value=78.4, step=0.1,
63
+ help='Engine coolant temperature in Β°C. Normal range: 74–83 Β°C.'
64
+ )
65
+
66
+ # ── Assemble input dataframe ──────────────────────────────────────────────
67
+ # Column names must exactly match those used during model training.
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 temp': lub_oil_temp,
74
+ 'Coolant temp': coolant_temp,
75
+ }])
76
+
77
+ # ── Prediction ────────────────────────────────────────────────────────────
78
+ if st.button('Predict Engine Condition'):
79
+ prediction = model.predict(input_data)[0]
80
+ probability = model.predict_proba(input_data)[0]
81
+
82
+ if prediction == 1:
83
+ st.error(
84
+ f'⚠️ **Faulty Engine Detected!** '
85
+ f'Confidence: {probability[1]:.1%} '
86
+ f'\n\nImmediate inspection is recommended to prevent breakdown.'
87
+ )
88
+ else:
89
+ st.success(
90
+ f'βœ… **Engine is Normal.** '
91
+ f'Confidence: {probability[0]:.1%} '
92
+ f'\n\nAll sensor readings are within acceptable limits.'
93
+ )
94
+
95
+ st.subheader('Input Summary')
96
+ st.dataframe(input_data)
requirements.txt CHANGED
@@ -1,3 +1,10 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
1
+ # Define the Python package dependencies for the Streamlit application.
2
+ # These versions ensure reproducibility of the deployment environment.
3
+ pandas==2.2.2
4
+ huggingface_hub==0.32.6
5
+ streamlit==1.43.2
6
+ joblib==1.5.1
7
+ scikit-learn==1.6.0
8
+ xgboost==2.1.4
9
+ imbalanced-learn==0.12.4
10
+ mlflow==3.0.1