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

Update app.py

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