Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,36 +36,22 @@ st.markdown("""
|
|
| 36 |
|
| 37 |
|
| 38 |
# ---------------------------------------------------------
|
| 39 |
-
# TITLE
|
| 40 |
# ---------------------------------------------------------
|
| 41 |
st.title("ποΈ Predict Maintenance")
|
| 42 |
-
#st.write("The Predict Maintenance app is a tool to predict if an Engine needs any maintenance based on provided operating sensor parameters.")
|
| 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
|
| 47 |
-
|
| 48 |
-
*Suggested ranges are based on the data distribution used during training.*
|
| 49 |
""")
|
| 50 |
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
def formatted_number_input(title, hint, minval, maxval, defvalue, steps, valformat="%.4f"):
|
| 54 |
|
| 55 |
st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
|
| 56 |
|
| 57 |
-
#st.markdown(f"**{title}**")
|
| 58 |
-
#st.caption(hint)
|
| 59 |
-
|
| 60 |
-
#decimals=6
|
| 61 |
-
|
| 62 |
-
#raw = st.text_input(
|
| 63 |
-
#label="",
|
| 64 |
-
#value=f"{defvalue:.{decimals}f}",
|
| 65 |
-
#label_visibility="collapsed"
|
| 66 |
-
#)
|
| 67 |
-
|
| 68 |
-
#user_input = float(raw)
|
| 69 |
user_input = st.number_input(
|
| 70 |
label=f"{title} ({hint})",
|
| 71 |
#min_value=minval,
|
|
@@ -148,15 +134,13 @@ col_inputs, col_output = st.columns([3, 1.5])
|
|
| 148 |
# update contnent (input) in left input column
|
| 149 |
with col_inputs:
|
| 150 |
|
| 151 |
-
#
|
| 152 |
-
|
| 153 |
-
#st.markdown('<div class="section-title">π§ Engine Parameters</div>', unsafe_allow_html=True)
|
| 154 |
-
|
| 155 |
-
#with st.expander("π§ Engine Parameters", expanded=True):
|
| 156 |
with st.form("engine_form"):
|
| 157 |
|
|
|
|
| 158 |
st.subheader("π§ Engine Parameters")
|
| 159 |
-
|
|
|
|
| 160 |
col_left, col_right = st.columns(2)
|
| 161 |
|
| 162 |
# define inputs in left column
|
|
@@ -229,31 +213,21 @@ with col_inputs:
|
|
| 229 |
)
|
| 230 |
|
| 231 |
submitted = st.form_submit_button("π Check for Maintenance")
|
| 232 |
-
#st.markdown('</div>', unsafe_allow_html=True)
|
| 233 |
-
|
| 234 |
-
#st.markdown('</div>', unsafe_allow_html=True)
|
| 235 |
-
|
| 236 |
-
#st.markdown("---")
|
| 237 |
|
| 238 |
-
#col_btn1, col_btn2, col_btn3 = st.columns([1,2,1])
|
| 239 |
|
| 240 |
with col_output:
|
| 241 |
|
| 242 |
-
#
|
| 243 |
-
|
| 244 |
-
#st.markdown('<div class="section-title">π§ Prediction Result</div>', unsafe_allow_html=True)
|
| 245 |
-
|
| 246 |
output_placeholder = st.empty()
|
| 247 |
probability_placeholder = st.empty()
|
| 248 |
details_placeholder = st.empty()
|
| 249 |
|
| 250 |
-
st.markdown("""<div style="border:2px solid #22c55e; border-radius:16px; padding:20px; background-color:#111827;">""", unsafe_allow_html=True)
|
| 251 |
|
| 252 |
# ==========================
|
| 253 |
# Single Value Prediction
|
| 254 |
# ==========================
|
| 255 |
-
#if st.button("Check for Maintenance"):
|
| 256 |
with st.expander("π§ Prediction Result", expanded=True):
|
|
|
|
| 257 |
if submitted:
|
| 258 |
|
| 259 |
# extract the data collected into a structure
|
|
@@ -297,11 +271,12 @@ with col_output:
|
|
| 297 |
# dispaly probability of failur metric
|
| 298 |
probability_placeholder.metric("Failure Probability", formatted_prob)
|
| 299 |
|
| 300 |
-
|
| 301 |
details_placeholder.markdown(f"""
|
| 302 |
-
*Model
|
| 303 |
-
*
|
| 304 |
-
|
|
|
|
| 305 |
""")
|
| 306 |
|
| 307 |
else:
|
|
@@ -324,7 +299,6 @@ with col_output:
|
|
| 324 |
else:
|
| 325 |
output_placeholder.error(f"β οΈ Error processing request- Status Code : {response.status_code}")
|
| 326 |
|
| 327 |
-
#st.markdown('</div>', unsafe_allow_html=True)
|
| 328 |
|
| 329 |
# ==============================
|
| 330 |
# Batch Prediction
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
# ---------------------------------------------------------
|
| 39 |
+
# Set Page TITLE and additional information for consumer
|
| 40 |
# ---------------------------------------------------------
|
| 41 |
st.title("ποΈ Predict Maintenance")
|
|
|
|
|
|
|
|
|
|
| 42 |
st.markdown("""
|
| 43 |
+
The Predict Maintenance app help to predict if an engine needs maintenance based on operating sensor parameters.
|
| 44 |
+
*Suggested ranges are based on known information - input is not restricted to the specified range*
|
|
|
|
| 45 |
""")
|
| 46 |
|
| 47 |
|
| 48 |
+
# generic function to provide input
|
| 49 |
+
# this is provided as an utiity to bring consistent user interface
|
| 50 |
+
# currently few parameters are used, rest or for later expansion
|
| 51 |
def formatted_number_input(title, hint, minval, maxval, defvalue, steps, valformat="%.4f"):
|
| 52 |
|
| 53 |
st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
user_input = st.number_input(
|
| 56 |
label=f"{title} ({hint})",
|
| 57 |
#min_value=minval,
|
|
|
|
| 134 |
# update contnent (input) in left input column
|
| 135 |
with col_inputs:
|
| 136 |
|
| 137 |
+
# using form for usre input, this proivides elegant interface
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
with st.form("engine_form"):
|
| 139 |
|
| 140 |
+
# set header string
|
| 141 |
st.subheader("π§ Engine Parameters")
|
| 142 |
+
|
| 143 |
+
# create two columsn so we can spread the input into two columns
|
| 144 |
col_left, col_right = st.columns(2)
|
| 145 |
|
| 146 |
# define inputs in left column
|
|
|
|
| 213 |
)
|
| 214 |
|
| 215 |
submitted = st.form_submit_button("π Check for Maintenance")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
|
|
|
| 217 |
|
| 218 |
with col_output:
|
| 219 |
|
| 220 |
+
# define place holders for output display
|
|
|
|
|
|
|
|
|
|
| 221 |
output_placeholder = st.empty()
|
| 222 |
probability_placeholder = st.empty()
|
| 223 |
details_placeholder = st.empty()
|
| 224 |
|
|
|
|
| 225 |
|
| 226 |
# ==========================
|
| 227 |
# Single Value Prediction
|
| 228 |
# ==========================
|
|
|
|
| 229 |
with st.expander("π§ Prediction Result", expanded=True):
|
| 230 |
+
# dispaly result only after submit is done
|
| 231 |
if submitted:
|
| 232 |
|
| 233 |
# extract the data collected into a structure
|
|
|
|
| 271 |
# dispaly probability of failur metric
|
| 272 |
probability_placeholder.metric("Failure Probability", formatted_prob)
|
| 273 |
|
| 274 |
+
# Display additional information
|
| 275 |
details_placeholder.markdown(f"""
|
| 276 |
+
*Model :* XGBoost
|
| 277 |
+
*Inference :* Real-time
|
| 278 |
+
|
| 279 |
+
*Note* : Probability of 50% and above is considered is suggested for maintenance
|
| 280 |
""")
|
| 281 |
|
| 282 |
else:
|
|
|
|
| 299 |
else:
|
| 300 |
output_placeholder.error(f"β οΈ Error processing request- Status Code : {response.status_code}")
|
| 301 |
|
|
|
|
| 302 |
|
| 303 |
# ==============================
|
| 304 |
# Batch Prediction
|