Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 47 |
-
|
| 48 |
-
|
| 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 |
-
|
|
|
|
| 93 |
background-color: #0f141a;
|
| 94 |
border: 1px solid #2a2f36;
|
| 95 |
border-radius: 12px;
|
| 96 |
-
padding:
|
| 97 |
-
margin-bottom:
|
| 98 |
}
|
|
|
|
|
|
|
| 99 |
.card-title {
|
| 100 |
-
font-size: 1.
|
| 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.
|
| 120 |
-
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
# define inputs in left column
|
| 125 |
-
with col_left:
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 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 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
output_placeholder = st.empty()
|
| 207 |
-
details_placeholder = st.empty()
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
#
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
## Get Sales Prediction Value
|
| 240 |
-
prediction_from_backend = result.get ("prediction") # Extract only the value
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
else:
|
| 246 |
-
output_placeholder.success("✅ Engine operating normally")
|
| 247 |
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
|
| 254 |
-
|
|
|
|
| 255 |
|
|
|
|
| 256 |
error_str = result.get ("message")
|
| 257 |
-
|
| 258 |
-
output_placeholder.error(f"⚠️ {error_str}")
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 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 |
-
|
| 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
|