subratm62 commited on
Commit
39c3820
Β·
verified Β·
1 Parent(s): 737c45e

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +151 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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 "7860" and make it accessible externally
23
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ # ---------------------------------------------------
7
+ # Page config
8
+ # ---------------------------------------------------
9
+
10
+ st.set_page_config(
11
+ page_title="Predictive Maintenance Engine Risk Predictor",
12
+ layout="centered"
13
+ )
14
+
15
+ # ---------------------------------------------------
16
+ # Load Model from Hugging Face
17
+ # ---------------------------------------------------
18
+
19
+ REPO_ID = "subratm62/predictive-maintenance"
20
+ MODEL_FILE = "predictive_maintenance_pipeline.joblib"
21
+
22
+ @st.cache_resource
23
+ def load_model():
24
+ model_path = hf_hub_download(
25
+ repo_id=REPO_ID,
26
+ filename=MODEL_FILE
27
+ )
28
+ return joblib.load(model_path)
29
+
30
+ model = load_model()
31
+
32
+ # Classification threshold (your tuned value)
33
+ classification_threshold = 0.50
34
+
35
+ # ---------------------------------------------------
36
+ # UI Header
37
+ # ---------------------------------------------------
38
+
39
+ st.title("πŸ”§ Predictive Maintenance β€” Engine Failure Risk")
40
+ st.write(
41
+ """
42
+ Enter live engine sensor readings to estimate **failure risk**.
43
+ This tool supports proactive maintenance decisions.
44
+ """
45
+ )
46
+
47
+ st.markdown("---")
48
+
49
+ # ---------------------------------------------------
50
+ # Sensor Inputs
51
+ # ---------------------------------------------------
52
+
53
+ st.subheader("Engine Sensor Inputs")
54
+
55
+ col1, col2 = st.columns(2)
56
+
57
+ with col1:
58
+ engine_rpm = st.number_input(
59
+ "Engine RPM",
60
+ min_value=0.0,
61
+ max_value=3000.0,
62
+ value=750.0
63
+ )
64
+
65
+ lub_oil_pressure = st.number_input(
66
+ "Lub Oil Pressure",
67
+ min_value=0.0,
68
+ max_value=10.0,
69
+ value=3.0
70
+ )
71
+
72
+ fuel_pressure = st.number_input(
73
+ "Fuel Pressure",
74
+ min_value=0.0,
75
+ max_value=25.0,
76
+ value=6.0
77
+ )
78
+
79
+ with col2:
80
+ coolant_pressure = st.number_input(
81
+ "Coolant Pressure",
82
+ min_value=0.0,
83
+ max_value=10.0,
84
+ value=2.0
85
+ )
86
+
87
+ lub_oil_temp = st.number_input(
88
+ "Lub Oil Temperature",
89
+ min_value=60.0,
90
+ max_value=120.0,
91
+ value=77.0
92
+ )
93
+
94
+ coolant_temp = st.number_input(
95
+ "Coolant Temperature",
96
+ min_value=50.0,
97
+ max_value=200.0,
98
+ value=78.0
99
+ )
100
+
101
+ st.markdown("---")
102
+
103
+ # ---------------------------------------------------
104
+ # Prepare input dataframe
105
+ # ---------------------------------------------------
106
+
107
+ input_data = pd.DataFrame([{
108
+ "Engine rpm": engine_rpm,
109
+ "Lub oil pressure": lub_oil_pressure,
110
+ "Fuel pressure": fuel_pressure,
111
+ "Coolant pressure": coolant_pressure,
112
+ "lub oil temp": lub_oil_temp,
113
+ "Coolant temp": coolant_temp
114
+ }])
115
+
116
+ # ---------------------------------------------------
117
+ # Prediction
118
+ # ---------------------------------------------------
119
+
120
+ if st.button("πŸ” Predict Failure Risk"):
121
+
122
+ probability = model.predict_proba(input_data)[0, 1]
123
+ prediction = int(probability >= classification_threshold)
124
+
125
+ st.subheader("Prediction Result")
126
+
127
+ if prediction == 1:
128
+ st.error(
129
+ "⚠ HIGH FAILURE RISK β€” Maintenance inspection recommended."
130
+ )
131
+ else:
132
+ st.success(
133
+ "βœ… Engine operating within normal range."
134
+ )
135
+
136
+ st.write(f"**Failure Probability:** {probability:.4f}")
137
+ st.write(f"**Decision Threshold:** {classification_threshold:.2f}")
138
+
139
+ # Business interpretation
140
+ if probability > 0.75:
141
+ st.warning("Critical condition β€” immediate inspection advised.")
142
+ elif probability > 0.50:
143
+ st.info("Moderate risk β€” schedule maintenance soon.")
144
+ else:
145
+ st.write("Low operational risk detected.")
146
+
147
+ st.markdown("---")
148
+
149
+ st.caption(
150
+ "Model hosted on Hugging Face | Experiment tracking via MLflow | Built with Streamlit"
151
+ )
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
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