Spaces:
Runtime error
Runtime error
File size: 12,097 Bytes
a9187b2 823fb02 7f26aad ea50094 34c68be 7ad3e6c 34c68be 12c018b 7ad3e6c b8f990b 34c68be 7ad3e6c d561456 a9187b2 05c1b8b 529ed2b 0e06bcd 05c1b8b 0e06bcd 05c1b8b 0e06bcd 05c1b8b ea50094 50b0cef 3442619 823fb02 12c018b f6fcf9b 366f701 f6fcf9b 366f701 f6fcf9b 12c018b f6fcf9b 12c018b f6fcf9b 12c018b f6fcf9b 12c018b f6fcf9b 12c018b 6a052fb 823fb02 12c018b 823fb02 6a052fb a9187b2 6a052fb 12c018b 7ad3e6c 9635cc4 7ad3e6c 9635cc4 7ad3e6c 529ed2b 366f701 529ed2b 3adc8cb 529ed2b 3adc8cb 529ed2b 3adc8cb 529ed2b 3adc8cb 529ed2b 3adc8cb 529ed2b 9635cc4 3adc8cb f9e0583 6a052fb 7ad3e6c 366f701 f0aa096 366f701 f0aa096 366f701 ba571dc 7ad3e6c ba571dc b8f990b ba571dc 7fa1a50 ba571dc e8e8596 7fa1a50 ba571dc 7fa1a50 f0aa096 7fa1a50 7ad3e6c ba571dc 7ad3e6c fcf77be ba571dc bc7f0f1 f9e0583 ba571dc f9e0583 ba571dc a9187b2 ba571dc f9e0583 ba571dc 102f58e 6a052fb 102f58e fcf77be 3adc8cb fcf77be 102f58e 3adc8cb 102f58e 48dec84 102f58e e8e8596 fcf77be 48dec84 102f58e fcf77be e8e8596 48dec84 3adc8cb 48dec84 102f58e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 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 196 197 198 199 200 201 202 203 204 205 206 207 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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | # import requests for interacting with backend
import requests
# import streamlit library for IO
import streamlit as st
# import pandas
import pandas as pd
# ---------------------------------------------------------
# PAGE CONFIG
# ---------------------------------------------------------
st.set_page_config(
page_title="Predictive Maintenenace App",
layout="wide"
)
# ---------------------------------------------------------
# TITLE
# ---------------------------------------------------------
#st.title("🏖️ Predict Engine Maintenance")
#st.write("The Predict Maintenance app is a tool to predict if an Engine needs any maintenance based on provided operating sensor parameters.")
#st.write("Fill in the details below and click **Predict** to see if the Engine needs maintenance to prevent from failure.")
# -----------------------------
# Title & Description
# -----------------------------
st.markdown("""
<style>
.block-container {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
}
</style>
""", unsafe_allow_html=True)
# ---------------------------------------------------------
# Set Page TITLE and additional information for consumer
# ---------------------------------------------------------
st.title("🏖️ Predict Maintenance")
st.markdown("""
The Predict Maintenance app help to predict if an engine needs maintenance based on operating sensor parameters.
*Suggested ranges are based on known information - input is not restricted to the specified range*
""")
# generic function to provide input
# this is provided as an utiity to bring consistent user interface
# currently few parameters are used, rest or for later expansion
def formatted_number_input(title, hint, minval, maxval, defvalue, steps, valformat="%.4f"):
st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
user_input = st.number_input(
label=f"{title} ({hint})",
#min_value=minval,
#max_value=maxval,
value=defvalue,
#step=steps,
format=valformat,
#label_visibility="collapsed"
)
return user_input
st.markdown("""
<style>
/* Reduce top padding */
.block-container {
padding-top: 1rem;
padding-bottom: 1rem;
}
/* Shared card styling */
.card {
border-radius: 16px;
padding: 22px;
margin-bottom: 20px;
transition: 0.3s ease-in-out;
}
/* INPUT CARD */
.input-card {
background: linear-gradient(145deg, #0f172a, #111827);
border: 1px solid #334155;
box-shadow: 0 0 0 1px rgba(59,130,246,0.15);
}
/* OUTPUT CARD */
.output-card {
background: linear-gradient(145deg, #111827, #0b1220);
border: 1px solid #16a34a;
box-shadow: 0 0 12px rgba(34,197,94,0.25);
}
/* Card title */
.card-title {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 16px;
letter-spacing: 0.5px;
}
/* Button styling */
div.stButton > button {
width: 100%;
border-radius: 10px;
height: 3em;
font-weight: 600;
background: linear-gradient(90deg, #2563eb, #1d4ed8);
color: white;
border: none;
}
div.stButton > button:hover {
background: linear-gradient(90deg, #1d4ed8, #1e40af);
}
</style>
""", unsafe_allow_html=True)
# ====================================
# Section : Capture Engine Parameters
# ====================================
#st.subheader ("Engine Parameters")
# divide UI into two column layout by defining two columns
# left column is used for input and right for output
col_inputs, col_output = st.columns([3, 1.5])
# update contnent (input) in left input column
with col_inputs:
# using form for usre input, this proivides elegant interface
with st.form("engine_form"):
# set header string
st.subheader("🔧 Engine Parameters")
# create two columsn so we can spread the input into two columns
col_left, col_right = st.columns(2)
# define inputs in left column
with col_left:
rpm = formatted_number_input(
"Engine RPM",
"50 to 2500",
minval=50.0,
maxval=2500.0,
defvalue=735.0,
steps=10.0,
valformat="%.2f"
)
oil_pressure = formatted_number_input(
"Lubricating oil pressure in kPa",
"0.001 to 10.0",
minval=0.001,
maxval=10.0,
defvalue=3.300000,
steps=0.001,
valformat="%.6f"
)
fuel_pressure = formatted_number_input(
"Fuel Pressure in kPa",
"0.01 to 25.0",
minval=0.01,
maxval=25.0,
defvalue=6.500000,
steps=0.01,
valformat="%.6f"
)
# define inputs in left column
with col_right:
coolant_pressure = formatted_number_input(
"Coolant Pressure in kPa",
"0.01 to 10.0",
minval=0.01,
maxval=10.0,
defvalue=2.250000,
steps=0.10,
valformat="%.6f"
)
lub_oil_temp = formatted_number_input(
"Lubricating oil Temperature in °C",
"50.0 to 100.0",
minval=50.0,
maxval=100.0,
defvalue=75.0,
steps=0.1,
valformat="%.6f"
)
coolant_temp = formatted_number_input(
"Coolant Temperature in °C",
"50.0 to 200.0",
minval=50.0,
maxval=200.0,
defvalue=75.000000,
steps=0.1,
valformat="%.6f"
)
submitted = st.form_submit_button("🚀 Check Maintenance")
with col_output:
# define place holders for output display
output_placeholder = st.empty()
probability_placeholder = st.empty()
details_placeholder = st.empty()
# ==========================
# Single Value Prediction
# ==========================
with st.expander("🧠 Prediction Result", expanded=True):
# dispaly result only after submit is done
if submitted:
# extract the data collected into a structure
input_data = {
'Engine_rpm' : float(rpm),
'Lub_oil_pressure' : float(oil_pressure),
'Fuel_pressure' : float(fuel_pressure),
'Coolant_pressure' : float(coolant_pressure),
'lub_oil_temp' : float(lub_oil_temp),
'Coolant_temp' : float(coolant_temp),
}
input_df = pd.DataFrame([input_data])
response = requests.post (
"https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
json=input_data
)
if response.status_code == 200:
## get result as json
result = response.json ()
resp_status = result.get ("status")
if resp_status == "success":
## Get Sales Prediction, probability Values
prediction_from_backend = result.get ("prediction") # Extract only the value
probability = result.get ("probability") # Extract only the value
# convert probability into % for representation
formatted_prob = f"{probability * 100:.2f}%"
# generate output string
if prediction_from_backend == 1:
output_placeholder.error("⚠️ Engine likely needs maintenance")
else:
output_placeholder.success("✅ Engine operating normally")
# dispaly probability of failur metric
probability_placeholder.metric("Failure Probability", formatted_prob)
# Display additional information
details_placeholder.markdown(f"""
*Model :* XGBoost
*Inference :* Real-time
*Note* : Probability of 50% and above is considered to suggested for Maintenance.
""")
# Show the etails of data frame prepared from user input
st.subheader("📦 Input Data Summary")
st.dataframe (input_df)
else:
error_str = result.get ("message")
output_placeholder.error(f"⚠️ {error_str}")
elif response.status_code == 400 or response.status_code == 500: # known errors
## get result as json
result = response.json ()
# get error message
error_str = result.get ("message")
# show error message
output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}, error : {error_str}")
else:
output_placeholder.error(f"⚠️ Error processing request- Status Code : {response.status_code}")
# ==============================
# Batch Prediction
# ==============================
st.markdown("---")
st.subheader ("Batch Prediction for Engine Maintenance")
st.markdown("""
*Select csv file with engine sensor parameters to find prediction for all readings*
""")
file = st.file_uploader ("Upload CSV file", type=["csv"])
if file is not None and st.button("🚀 Check Maintenance"):
inputfile = {"file": (file.name, file.getvalue(), "text/csv")}
response = requests.post(
"https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenanceForBatch",
files=inputfile
)
if response.status_code == 200:
result = response.json ()
resp_status = result.get ("status")
if resp_status == "success":
## Get Sales Prediction Value
predictions_from_backend = result.get ("predictions") # Extract only the value
## get probabbilities from back end
probabilities = result.get ("probabilities") # Extract only the value
# read input data into data frame
input_df = pd.read_csv(file)
# Ensure lengths match
if len(predictions_from_backend) == len(input_df):
# Add prediction and probability column
input_df["Prediction"] = predictions_from_backend
input_df["Probability"] = probabilities
st.success("Batch prediction completed successfully")
st.markdown("""
*Prediction : 1 deontes Maintenance is needed*
*Probability : Indicates failure probability and value ranges from 0.0 to 1.0. Value of 0.5 (50%) and above is suggested for Maintenance*
""")
# Show combined dataframe
st.dataframe(input_df, use_container_width=True)
else:
st.error("Prediction count does not match input records")
else:
error_str = result.get ("message")
st.error(error_str)
elif response.status_code == 400 or response.status_code == 500: # known errors
## get result as json
result = response.json ()
error_str = result.get ("message")
st.error (f"Error processing request- Status Code : {response.status_code}, error : {error_str}")
else:
st.error (f"Error processing request- Status Code : {response.status_code}")
|