harishsohani commited on
Commit
b8f990b
·
verified ·
1 Parent(s): ec55053

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -152
app.py CHANGED
@@ -43,18 +43,10 @@ st.title("🏖️ Predict Maintenance")
43
  #st.write("Fill in the details below and click **Check for Maintenance** to see if the Engine needs maintenance to prevent from failure.")
44
  #st.write("Suggested Ranges are based on the Range of Values model trained on.")
45
  st.markdown("""
46
- <style>
47
- .intro-text p {
48
- margin-bottom: 0.4rem;
49
- }
50
- </style>
51
-
52
- <div class="intro-text">
53
- <p>The Predict Maintenance app is a tool to predict if an Engine needs any maintenance based on provided operating sensor parameters.</p>
54
- <p>Fill in the details below and click <b>Check for Maintenance</b> to see if the Engine needs maintenance.</p>
55
- <p><i>Suggested ranges are based on the range of values the model was trained on.</i></p>
56
- </div>
57
- """, unsafe_allow_html=True)
58
 
59
 
60
 
@@ -89,15 +81,18 @@ def formatted_number_input(title, hint, minval, maxval, defvalue, steps, valform
89
 
90
  st.markdown("""
91
  <style>
92
- .card {
 
93
  background-color: #0f141a;
94
  border: 1px solid #2a2f36;
95
  border-radius: 12px;
96
- padding: 18px;
97
- margin-bottom: 20px;
98
  }
 
 
99
  .card-title {
100
- font-size: 1.1rem;
101
  font-weight: 600;
102
  margin-bottom: 12px;
103
  }
@@ -116,81 +111,80 @@ col_inputs, col_output = st.columns([3, 1.5])
116
  # update contnent (input) in left input column
117
  with col_inputs:
118
 
119
- st.markdown('<div class="card">', unsafe_allow_html=True)
120
- st.markdown('<div class="card-title">🔧 Engine Parameters</div>', unsafe_allow_html=True)
121
 
122
- col_left, col_right = st.columns(2)
123
-
124
- # define inputs in left column
125
- with col_left:
126
 
127
- rpm = formatted_number_input(
128
- "Lubricating oil pressure (kPa)",
129
- "50 to 2500",
130
- minval=50.0,
131
- maxval=2500.0,
132
- defvalue=735.0,
133
- steps=10.0,
134
- valformat="%.2f"
135
- )
136
-
137
 
138
- oil_pressure = formatted_number_input(
139
- "Lubricating oil pressure (kPa)",
140
- "0.001 to 10.0",
141
- minval=0.001,
142
- maxval=10.0,
143
- defvalue=3.300000,
144
- steps=0.001,
145
- valformat="%.6f"
146
- )
147
-
148
-
149
- fuel_pressure = formatted_number_input(
150
- "Fuel Pressure (kPa)",
151
- "0.01 to 25.0",
152
- minval=0.01,
153
- maxval=25.0,
154
- defvalue=6.500000,
155
- steps=0.01,
156
- valformat="%.6f"
157
- )
158
-
159
- # define inputs in left column
160
- with col_right:
161
- coolant_pressure = formatted_number_input(
162
- "Coolant Pressure (kPa)",
163
- "0.01 to 10.0",
164
- minval=0.01,
165
- maxval=10.0,
166
- defvalue=2.250000,
167
- steps=0.10,
168
- valformat="%.6f"
169
- )
170
-
171
-
172
- lub_oil_temp = formatted_number_input(
173
- "Lubricating oil Temperature (°C)",
174
- "50.0 to 100.0",
175
- minval=50.0,
176
- maxval=100.0,
177
- defvalue=75.0,
178
- steps=0.1,
179
- valformat="%.6f"
180
- )
181
-
182
-
183
- coolant_temp = formatted_number_input(
184
- "Coolant Temperature (°C)",
185
- "50.0 to 200.0",
186
- minval=50.0,
187
- maxval=200.0,
188
- defvalue=75.000000,
189
- steps=0.1,
190
- valformat="%.6f"
191
- )
192
-
193
- st.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
194
 
195
  #st.markdown('</div>', unsafe_allow_html=True)
196
 
@@ -200,79 +194,78 @@ with col_inputs:
200
 
201
  with col_output:
202
 
203
- st.markdown('<div class="card">', unsafe_allow_html=True)
204
- st.markdown('<div class="card-title">🧠 Prediction Result</div>', unsafe_allow_html=True)
205
-
206
- output_placeholder = st.empty()
207
- details_placeholder = st.empty()
208
 
209
- # ==========================
210
- # Single Value Prediction
211
- # ==========================
212
- if st.button("Check fo Maintenance"):
213
-
214
- # extract the data collected into a structure
215
- input_data = {
216
- 'Engine_rpm' : float(rpm),
217
- 'Lub_oil_pressure' : float(oil_pressure),
218
- 'Fuel_pressure' : float(fuel_pressure),
219
- 'Coolant_pressure' : float(coolant_pressure),
220
- 'lub_oil_temp' : float(lub_oil_temp),
221
- 'Coolant_temp' : float(coolant_temp),
222
- }
223
-
224
- input_df = pd.DataFrame([input_data])
225
-
226
- response = requests.post (
227
- "https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
228
- json=input_data
229
- )
230
-
231
- if response.status_code == 200:
232
- ## get result as json
233
- result = response.json ()
234
-
235
- resp_status = result.get ("status")
236
-
237
- if resp_status == "success":
238
-
239
- ## Get Sales Prediction Value
240
- prediction_from_backend = result.get ("prediction") # Extract only the value
241
 
242
- # generate output string
243
- if prediction_from_backend == 1:
244
- output_placeholder.error("⚠️ Engine likely needs maintenance")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  else:
246
- output_placeholder.success("✅ Engine operating normally")
247
 
248
- details_placeholder.markdown("""
249
- **Model:** XGBoost
250
- **Threshold:** 0.5
251
- **Inference:** Real-time
252
- """)
253
 
254
- else:
 
255
 
 
256
  error_str = result.get ("message")
257
-
258
- output_placeholder.error(f"⚠️ {error_str}")
259
 
260
- elif response.status_code == 400 or response.status_code == 500: # known errors
261
-
262
- ## get result as json
263
- result = response.json ()
264
-
265
- # get error message
266
- error_str = result.get ("message")
267
-
268
- # show error message
269
- output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}, error : {error_str}")
270
-
271
- else:
272
- output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}")
273
 
274
- st.markdown('</div>', unsafe_allow_html=True)
275
-
276
 
277
  # ==============================
278
  # Batch Prediction
 
43
  #st.write("Fill in the details below and click **Check for Maintenance** to see if the Engine needs maintenance to prevent from failure.")
44
  #st.write("Suggested Ranges are based on the Range of Values model trained on.")
45
  st.markdown("""
46
+ The Predict Maintenance app is a tool to predict if an engine needs maintenance based on operating sensor parameters.
47
+ Fill in the details below and click **Check for Maintenance** to see the prediction.
48
+ *Suggested ranges are based on the data distribution used during training.*
49
+ """)
 
 
 
 
 
 
 
 
50
 
51
 
52
 
 
81
 
82
  st.markdown("""
83
  <style>
84
+ /* Card container */
85
+ [data-testid="stVerticalBlock"] > [data-testid="stVerticalBlock"] {
86
  background-color: #0f141a;
87
  border: 1px solid #2a2f36;
88
  border-radius: 12px;
89
+ padding: 16px;
90
+ margin-bottom: 16px;
91
  }
92
+
93
+ /* Card title spacing */
94
  .card-title {
95
+ font-size: 1.05rem;
96
  font-weight: 600;
97
  margin-bottom: 12px;
98
  }
 
111
  # update contnent (input) in left input column
112
  with col_inputs:
113
 
114
+ with st.container():
115
+ st.markdown('<div class="card-title">🔧 Engine Parameters</div>', unsafe_allow_html=True)
116
 
117
+ col_left, col_right = st.columns(2)
 
 
 
118
 
119
+ # define inputs in left column
120
+ with col_left:
 
 
 
 
 
 
 
 
121
 
122
+ rpm = formatted_number_input(
123
+ "Engine RPM",
124
+ "50 to 2500",
125
+ minval=50.0,
126
+ maxval=2500.0,
127
+ defvalue=735.0,
128
+ steps=10.0,
129
+ valformat="%.2f"
130
+ )
131
+
132
+
133
+ oil_pressure = formatted_number_input(
134
+ "Lubricating oil pressure (kPa)",
135
+ "0.001 to 10.0",
136
+ minval=0.001,
137
+ maxval=10.0,
138
+ defvalue=3.300000,
139
+ steps=0.001,
140
+ valformat="%.6f"
141
+ )
142
+
143
+
144
+ fuel_pressure = formatted_number_input(
145
+ "Fuel Pressure (kPa)",
146
+ "0.01 to 25.0",
147
+ minval=0.01,
148
+ maxval=25.0,
149
+ defvalue=6.500000,
150
+ steps=0.01,
151
+ valformat="%.6f"
152
+ )
153
+
154
+ # define inputs in left column
155
+ with col_right:
156
+ coolant_pressure = formatted_number_input(
157
+ "Coolant Pressure (kPa)",
158
+ "0.01 to 10.0",
159
+ minval=0.01,
160
+ maxval=10.0,
161
+ defvalue=2.250000,
162
+ steps=0.10,
163
+ valformat="%.6f"
164
+ )
165
+
166
+
167
+ lub_oil_temp = formatted_number_input(
168
+ "Lubricating oil Temperature (°C)",
169
+ "50.0 to 100.0",
170
+ minval=50.0,
171
+ maxval=100.0,
172
+ defvalue=75.0,
173
+ steps=0.1,
174
+ valformat="%.6f"
175
+ )
176
+
177
+
178
+ coolant_temp = formatted_number_input(
179
+ "Coolant Temperature (°C)",
180
+ "50.0 to 200.0",
181
+ minval=50.0,
182
+ maxval=200.0,
183
+ defvalue=75.000000,
184
+ steps=0.1,
185
+ valformat="%.6f"
186
+ )
187
+
188
 
189
  #st.markdown('</div>', unsafe_allow_html=True)
190
 
 
194
 
195
  with col_output:
196
 
197
+ with st.container():
198
+ st.markdown('<div class="card-title">🧠 Prediction Result</div>', unsafe_allow_html=True)
 
 
 
199
 
200
+ output_placeholder = st.empty()
201
+ details_placeholder = st.empty()
202
+
203
+ # ==========================
204
+ # Single Value Prediction
205
+ # ==========================
206
+ if st.button("Check for Maintenance"):
207
+
208
+ # extract the data collected into a structure
209
+ input_data = {
210
+ 'Engine_rpm' : float(rpm),
211
+ 'Lub_oil_pressure' : float(oil_pressure),
212
+ 'Fuel_pressure' : float(fuel_pressure),
213
+ 'Coolant_pressure' : float(coolant_pressure),
214
+ 'lub_oil_temp' : float(lub_oil_temp),
215
+ 'Coolant_temp' : float(coolant_temp),
216
+ }
217
+
218
+ input_df = pd.DataFrame([input_data])
219
+
220
+ response = requests.post (
221
+ "https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
222
+ json=input_data
223
+ )
224
+
225
+ if response.status_code == 200:
226
+ ## get result as json
227
+ result = response.json ()
228
+
229
+ resp_status = result.get ("status")
 
 
230
 
231
+ if resp_status == "success":
232
+
233
+ ## Get Sales Prediction Value
234
+ prediction_from_backend = result.get ("prediction") # Extract only the value
235
+
236
+ # generate output string
237
+ if prediction_from_backend == 1:
238
+ output_placeholder.error("⚠️ Engine likely needs maintenance")
239
+ else:
240
+ output_placeholder.success("✅ Engine operating normally")
241
+
242
+ details_placeholder.markdown("""
243
+ **Model:** XGBoost
244
+ **Threshold:** 0.5
245
+ **Inference:** Real-time
246
+ """)
247
+
248
  else:
 
249
 
250
+ error_str = result.get ("message")
251
+
252
+ output_placeholder.error(f"⚠️ {error_str}")
253
+
254
+ elif response.status_code == 400 or response.status_code == 500: # known errors
255
 
256
+ ## get result as json
257
+ result = response.json ()
258
 
259
+ # get error message
260
  error_str = result.get ("message")
 
 
261
 
262
+ # show error message
263
+ output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}, error : {error_str}")
264
+
265
+ else:
266
+ output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}")
 
 
 
 
 
 
 
 
267
 
268
+
 
269
 
270
  # ==============================
271
  # Batch Prediction