Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,88 +99,105 @@ def formatted_number_input(title, hint, minval, maxval, defvalue, steps, valform
|
|
| 99 |
return user_input
|
| 100 |
|
| 101 |
|
|
|
|
| 102 |
# ====================================
|
| 103 |
# Section : Capture Engine Parameters
|
| 104 |
# ====================================
|
| 105 |
st.subheader ("Engine Parameters")
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
"50 to 2500",
|
| 114 |
-
minval=50.0,
|
| 115 |
-
maxval=2500.0,
|
| 116 |
-
defvalue=735.0,
|
| 117 |
-
steps=10.0,
|
| 118 |
-
valformat="%.2f"
|
| 119 |
-
)
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
oil_pressure = formatted_number_input(
|
| 123 |
-
"Lubricating oil pressure in kilopascals (kPa)",
|
| 124 |
-
"0.001 to 10.0",
|
| 125 |
-
minval=0.001,
|
| 126 |
-
maxval=10.0,
|
| 127 |
-
defvalue=3.300000,
|
| 128 |
-
steps=0.001,
|
| 129 |
-
valformat="%.6f"
|
| 130 |
-
)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
fuel_pressure = formatted_number_input(
|
| 134 |
-
"Fuel Pressure in kilopascals (kPa)",
|
| 135 |
-
"0.01 to 25.0",
|
| 136 |
-
minval=0.01,
|
| 137 |
-
maxval=25.0,
|
| 138 |
-
defvalue=6.500000,
|
| 139 |
-
steps=0.01,
|
| 140 |
-
valformat="%.6f"
|
| 141 |
-
)
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
"Coolant Pressure in kilopascals (kPa)",
|
| 146 |
-
"0.01 to 10.0",
|
| 147 |
-
minval=0.01,
|
| 148 |
-
maxval=10.0,
|
| 149 |
-
defvalue=2.250000,
|
| 150 |
-
steps=0.10,
|
| 151 |
-
valformat="%.6f"
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
lub_oil_temp = formatted_number_input(
|
| 156 |
-
"Lubricating oil Temperature in degrees Celsius (°C)",
|
| 157 |
-
"50.0 to 100.0",
|
| 158 |
-
minval=50.0,
|
| 159 |
-
maxval=100.0,
|
| 160 |
-
defvalue=75.0,
|
| 161 |
-
steps=0.1,
|
| 162 |
-
valformat="%.6f"
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
st.markdown(
|
| 179 |
|
| 180 |
-
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
# Single Value Prediction
|
| 185 |
# ==========================
|
| 186 |
if st.button("Check fo Maintenance"):
|
|
@@ -215,37 +232,43 @@ with col_btn2:
|
|
| 215 |
|
| 216 |
# generate output string
|
| 217 |
if prediction_from_backend == 1:
|
| 218 |
-
|
| 219 |
else:
|
| 220 |
-
|
| 221 |
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
else:
|
| 225 |
|
| 226 |
error_str = result.get ("message")
|
| 227 |
-
|
| 228 |
-
|
| 229 |
|
| 230 |
elif response.status_code == 400 or response.status_code == 500: # known errors
|
| 231 |
|
| 232 |
## get result as json
|
| 233 |
result = response.json ()
|
| 234 |
-
|
|
|
|
| 235 |
error_str = result.get ("message")
|
| 236 |
-
|
|
|
|
|
|
|
| 237 |
|
| 238 |
else:
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
# Show the etails of data frame prepared from user input
|
| 242 |
-
st.subheader("📦 Input Data Summary")
|
| 243 |
-
st.dataframe (input_df)
|
| 244 |
|
|
|
|
| 245 |
|
| 246 |
# ==============================
|
| 247 |
# Batch Prediction
|
| 248 |
# ==============================
|
|
|
|
|
|
|
| 249 |
st.subheader ("Batch Prediction for Engine Maintenance")
|
| 250 |
|
| 251 |
file = st.file_uploader ("Upload CSV file", type=["csv"])
|
|
|
|
| 99 |
return user_input
|
| 100 |
|
| 101 |
|
| 102 |
+
|
| 103 |
# ====================================
|
| 104 |
# Section : Capture Engine Parameters
|
| 105 |
# ====================================
|
| 106 |
st.subheader ("Engine Parameters")
|
| 107 |
|
| 108 |
+
# divide UI into two column layout by defining two columns
|
| 109 |
+
# left column is used for input and right for output
|
| 110 |
+
col_inputs, col_output = st.columns([3, 1.5])
|
| 111 |
|
| 112 |
+
# update contnent (input) in left input column
|
| 113 |
+
with col_inputs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
col_left, col_right = st.columns([1,1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
# define inputs in left column
|
| 118 |
+
with col_left:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
rpm = formatted_number_input(
|
| 121 |
+
"Lubricating oil pressure in kilopascals (kPa)",
|
| 122 |
+
"50 to 2500",
|
| 123 |
+
minval=50.0,
|
| 124 |
+
maxval=2500.0,
|
| 125 |
+
defvalue=735.0,
|
| 126 |
+
steps=10.0,
|
| 127 |
+
valformat="%.2f"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
oil_pressure = formatted_number_input(
|
| 132 |
+
"Lubricating oil pressure in kilopascals (kPa)",
|
| 133 |
+
"0.001 to 10.0",
|
| 134 |
+
minval=0.001,
|
| 135 |
+
maxval=10.0,
|
| 136 |
+
defvalue=3.300000,
|
| 137 |
+
steps=0.001,
|
| 138 |
+
valformat="%.6f"
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
fuel_pressure = formatted_number_input(
|
| 143 |
+
"Fuel Pressure in kilopascals (kPa)",
|
| 144 |
+
"0.01 to 25.0",
|
| 145 |
+
minval=0.01,
|
| 146 |
+
maxval=25.0,
|
| 147 |
+
defvalue=6.500000,
|
| 148 |
+
steps=0.01,
|
| 149 |
+
valformat="%.6f"
|
| 150 |
+
)
|
| 151 |
|
| 152 |
+
# define inputs in left column
|
| 153 |
+
with col_right:
|
| 154 |
+
coolant_pressure = formatted_number_input(
|
| 155 |
+
"Coolant Pressure in kilopascals (kPa)",
|
| 156 |
+
"0.01 to 10.0",
|
| 157 |
+
minval=0.01,
|
| 158 |
+
maxval=10.0,
|
| 159 |
+
defvalue=2.250000,
|
| 160 |
+
steps=0.10,
|
| 161 |
+
valformat="%.6f"
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
lub_oil_temp = formatted_number_input(
|
| 166 |
+
"Lubricating oil Temperature in degrees Celsius (°C)",
|
| 167 |
+
"50.0 to 100.0",
|
| 168 |
+
minval=50.0,
|
| 169 |
+
maxval=100.0,
|
| 170 |
+
defvalue=75.0,
|
| 171 |
+
steps=0.1,
|
| 172 |
+
valformat="%.6f"
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
coolant_temp = formatted_number_input(
|
| 177 |
+
"Coolant Temperature in degrees Celsius (°C)",
|
| 178 |
+
"50.0 to 200.0",
|
| 179 |
+
minval=50.0,
|
| 180 |
+
maxval=200.0,
|
| 181 |
+
defvalue=75.000000,
|
| 182 |
+
steps=0.1,
|
| 183 |
+
valformat="%.6f"
|
| 184 |
+
)
|
| 185 |
|
| 186 |
+
#st.markdown('</div>', unsafe_allow_html=True)
|
| 187 |
|
| 188 |
+
#st.markdown("---")
|
| 189 |
|
| 190 |
+
#col_btn1, col_btn2, col_btn3 = st.columns([1,2,1])
|
| 191 |
+
|
| 192 |
+
with col_output:
|
| 193 |
+
st.markdown("### 🧠 Prediction Result")
|
| 194 |
+
|
| 195 |
+
output_placeholder = st.empty()
|
| 196 |
+
details_placeholder = st.empty()
|
| 197 |
+
|
| 198 |
+
with col_output:
|
| 199 |
+
|
| 200 |
+
# ==========================
|
| 201 |
# Single Value Prediction
|
| 202 |
# ==========================
|
| 203 |
if st.button("Check fo Maintenance"):
|
|
|
|
| 232 |
|
| 233 |
# generate output string
|
| 234 |
if prediction_from_backend == 1:
|
| 235 |
+
output_placeholder.error("⚠️ Engine likely needs maintenance")
|
| 236 |
else:
|
| 237 |
+
output_placeholder.success("✅ Engine operating normally")
|
| 238 |
|
| 239 |
+
details_placeholder.markdown("""
|
| 240 |
+
**Model:** XGBoost
|
| 241 |
+
**Threshold:** 0.5
|
| 242 |
+
**Inference:** Real-time
|
| 243 |
+
""")
|
| 244 |
|
| 245 |
else:
|
| 246 |
|
| 247 |
error_str = result.get ("message")
|
| 248 |
+
|
| 249 |
+
output_placeholder.error(f"⚠️ {error_str}")
|
| 250 |
|
| 251 |
elif response.status_code == 400 or response.status_code == 500: # known errors
|
| 252 |
|
| 253 |
## get result as json
|
| 254 |
result = response.json ()
|
| 255 |
+
|
| 256 |
+
# get error message
|
| 257 |
error_str = result.get ("message")
|
| 258 |
+
|
| 259 |
+
# show error message
|
| 260 |
+
output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}, error : {error_str}")
|
| 261 |
|
| 262 |
else:
|
| 263 |
+
output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
+
|
| 266 |
|
| 267 |
# ==============================
|
| 268 |
# Batch Prediction
|
| 269 |
# ==============================
|
| 270 |
+
st.markdown("---")
|
| 271 |
+
|
| 272 |
st.subheader ("Batch Prediction for Engine Maintenance")
|
| 273 |
|
| 274 |
file = st.file_uploader ("Upload CSV file", type=["csv"])
|