Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ def formatted_number_input2(title, hint, minval, maxval, defvalue, steps, valfor
|
|
| 18 |
|
| 19 |
st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
|
| 20 |
|
| 21 |
-
col1, col2 = st.columns([
|
| 22 |
|
| 23 |
with col1:
|
| 24 |
st.markdown(
|
|
@@ -78,133 +78,141 @@ st.write("Fill in the details below and click **Predict** to see if the Engine n
|
|
| 78 |
# ====================================
|
| 79 |
st.subheader ("Engine Parameters")
|
| 80 |
|
| 81 |
-
|
| 82 |
-
"Lubricating oil pressure in kilopascals (kPa)",
|
| 83 |
-
"50 to 2500",
|
| 84 |
-
minval=50.0,
|
| 85 |
-
maxval=2500.0,
|
| 86 |
-
defvalue=735.0,
|
| 87 |
-
steps=10.0,
|
| 88 |
-
valformat="%.2f"
|
| 89 |
-
)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
oil_pressure = formatted_number_input2(
|
| 93 |
-
"Lubricating oil pressure in kilopascals (kPa)",
|
| 94 |
-
"0.001 to 10.0",
|
| 95 |
-
minval=0.001,
|
| 96 |
-
maxval=10.0,
|
| 97 |
-
defvalue=3.300000,
|
| 98 |
-
steps=0.001,
|
| 99 |
-
valformat="%.6f"
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
fuel_pressure = formatted_number_input2(
|
| 104 |
-
"Fuel Pressure in kilopascals (kPa)",
|
| 105 |
-
"0.01 to 25.0",
|
| 106 |
-
minval=0.01,
|
| 107 |
-
maxval=25.0,
|
| 108 |
-
defvalue=6.500000,
|
| 109 |
-
steps=0.01,
|
| 110 |
-
valformat="%.6f"
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
coolant_pressure = formatted_number_input2(
|
| 115 |
-
"Coolant Pressure in kilopascals (kPa)",
|
| 116 |
-
"0.01 to 10.0",
|
| 117 |
-
minval=0.01,
|
| 118 |
-
maxval=10.0,
|
| 119 |
-
defvalue=2.250000,
|
| 120 |
-
steps=0.10,
|
| 121 |
-
valformat="%.6f"
|
| 122 |
-
)
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
"Lubricating oil Temperature in degrees Celsius (°C)",
|
| 127 |
-
"50.0 to 100.0",
|
| 128 |
-
minval=50.0,
|
| 129 |
-
maxval=100.0,
|
| 130 |
-
defvalue=75.0,
|
| 131 |
-
steps=0.1,
|
| 132 |
-
valformat="%.6f"
|
| 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 |
-
"https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
|
| 166 |
-
json=input_data
|
| 167 |
-
)
|
| 168 |
|
| 169 |
-
|
| 170 |
-
## get result as json
|
| 171 |
-
result = response.json ()
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
else:
|
| 184 |
-
resultstr = "Engine does not need any maintenance"
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 190 |
error_str = result.get ("message")
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
error_str = result.get ("message")
|
| 200 |
-
st.error (f"Error processing request- Status Code : {response.status_code}, error : {error_str}")
|
| 201 |
-
|
| 202 |
-
else:
|
| 203 |
-
st.error (f"Error processing request- Status Code : {response.status_code}")
|
| 204 |
-
|
| 205 |
-
# Show the etails of data frame prepared from user input
|
| 206 |
-
st.subheader("📦 Input Data Summary")
|
| 207 |
-
st.dataframe (input_df)
|
| 208 |
|
| 209 |
|
| 210 |
# ==============================
|
|
|
|
| 18 |
|
| 19 |
st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
|
| 20 |
|
| 21 |
+
col1, col2 = st.columns([2.5, 1], vertical_alignment="center")
|
| 22 |
|
| 23 |
with col1:
|
| 24 |
st.markdown(
|
|
|
|
| 78 |
# ====================================
|
| 79 |
st.subheader ("Engine Parameters")
|
| 80 |
|
| 81 |
+
col_left, col_right = st.columns([1,1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
with col_left:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
rpm = formatted_number_input2(
|
| 86 |
+
"Lubricating oil pressure in kilopascals (kPa)",
|
| 87 |
+
"50 to 2500",
|
| 88 |
+
minval=50.0,
|
| 89 |
+
maxval=2500.0,
|
| 90 |
+
defvalue=735.0,
|
| 91 |
+
steps=10.0,
|
| 92 |
+
valformat="%.2f"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
oil_pressure = formatted_number_input2(
|
| 97 |
+
"Lubricating oil pressure in kilopascals (kPa)",
|
| 98 |
+
"0.001 to 10.0",
|
| 99 |
+
minval=0.001,
|
| 100 |
+
maxval=10.0,
|
| 101 |
+
defvalue=3.300000,
|
| 102 |
+
steps=0.001,
|
| 103 |
+
valformat="%.6f"
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
fuel_pressure = formatted_number_input2(
|
| 108 |
+
"Fuel Pressure in kilopascals (kPa)",
|
| 109 |
+
"0.01 to 25.0",
|
| 110 |
+
minval=0.01,
|
| 111 |
+
maxval=25.0,
|
| 112 |
+
defvalue=6.500000,
|
| 113 |
+
steps=0.01,
|
| 114 |
+
valformat="%.6f"
|
| 115 |
+
)
|
| 116 |
|
| 117 |
+
with col_right:
|
| 118 |
+
coolant_pressure = formatted_number_input2(
|
| 119 |
+
"Coolant Pressure in kilopascals (kPa)",
|
| 120 |
+
"0.01 to 10.0",
|
| 121 |
+
minval=0.01,
|
| 122 |
+
maxval=10.0,
|
| 123 |
+
defvalue=2.250000,
|
| 124 |
+
steps=0.10,
|
| 125 |
+
valformat="%.6f"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
lub_oil_temp = formatted_number_input2(
|
| 130 |
+
"Lubricating oil Temperature in degrees Celsius (°C)",
|
| 131 |
+
"50.0 to 100.0",
|
| 132 |
+
minval=50.0,
|
| 133 |
+
maxval=100.0,
|
| 134 |
+
defvalue=75.0,
|
| 135 |
+
steps=0.1,
|
| 136 |
+
valformat="%.6f"
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
coolant_temp = formatted_number_input2(
|
| 141 |
+
"Coolant Temperature in degrees Celsius (°C)",
|
| 142 |
+
"50.0 to 200.0",
|
| 143 |
+
minval=50.0,
|
| 144 |
+
maxval=200.0,
|
| 145 |
+
defvalue=75.000000,
|
| 146 |
+
steps=0.1,
|
| 147 |
+
valformat="%.6f"
|
| 148 |
+
)
|
| 149 |
|
| 150 |
+
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
col_btn1, col_btn2, col_btn3 = st.columns([1,2,1])
|
|
|
|
|
|
|
| 153 |
|
| 154 |
+
with col_btn2:
|
| 155 |
+
# ==========================
|
| 156 |
+
# Single Value Prediction
|
| 157 |
+
# ==========================
|
| 158 |
+
if st.button("Check fo Maintenance"):
|
| 159 |
+
|
| 160 |
+
# extract the data collected into a structure
|
| 161 |
+
input_data = {
|
| 162 |
+
'Engine_rpm' : float(rpm),
|
| 163 |
+
'Lub_oil_pressure' : float(oil_pressure),
|
| 164 |
+
'Fuel_pressure' : float(fuel_pressure),
|
| 165 |
+
'Coolant_pressure' : float(coolant_pressure),
|
| 166 |
+
'lub_oil_temp' : float(lub_oil_temp),
|
| 167 |
+
'Coolant_temp' : float(coolant_temp),
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
input_df = pd.DataFrame([input_data])
|
| 171 |
+
|
| 172 |
+
response = requests.post (
|
| 173 |
+
"https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
|
| 174 |
+
json=input_data
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
if response.status_code == 200:
|
| 178 |
+
## get result as json
|
| 179 |
+
result = response.json ()
|
| 180 |
|
| 181 |
+
resp_status = result.get ("status")
|
| 182 |
+
|
| 183 |
+
if resp_status == "success":
|
| 184 |
+
|
| 185 |
+
## Get Sales Prediction Value
|
| 186 |
+
prediction_from_backend = result.get ("prediction") # Extract only the value
|
| 187 |
+
|
| 188 |
+
# generate output string
|
| 189 |
+
if prediction_from_backend == 1:
|
| 190 |
+
resultstr = "Engine **likely** needs maintenance."
|
| 191 |
+
else:
|
| 192 |
+
resultstr = "Engine does not need any maintenance"
|
| 193 |
+
|
| 194 |
+
st.success(resultstr)
|
| 195 |
+
|
| 196 |
else:
|
|
|
|
| 197 |
|
| 198 |
+
error_str = result.get ("message")
|
| 199 |
+
|
| 200 |
+
st.error(error_str)
|
| 201 |
+
|
| 202 |
+
elif response.status_code == 400 or response.status_code == 500: # known errors
|
| 203 |
|
| 204 |
+
## get result as json
|
| 205 |
+
result = response.json ()
|
| 206 |
+
|
| 207 |
error_str = result.get ("message")
|
| 208 |
+
st.error (f"Error processing request- Status Code : {response.status_code}, error : {error_str}")
|
| 209 |
+
|
| 210 |
+
else:
|
| 211 |
+
st.error (f"Error processing request- Status Code : {response.status_code}")
|
| 212 |
+
|
| 213 |
+
# Show the etails of data frame prepared from user input
|
| 214 |
+
st.subheader("📦 Input Data Summary")
|
| 215 |
+
st.dataframe (input_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
|
| 218 |
# ==============================
|