Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -205,3 +205,60 @@ if st.button("Check fo Maintenance"):
|
|
| 205 |
# Show the etails of data frame prepared from user input
|
| 206 |
st.subheader("📦 Input Data Summary")
|
| 207 |
st.dataframe (input_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# ==============================
|
| 211 |
+
# Batch Prediction
|
| 212 |
+
# ==============================
|
| 213 |
+
st.subheader ("Batch Prediction for Engine Maintenance")
|
| 214 |
+
|
| 215 |
+
file = st.file_uploader ("Upload CSV file", type=["csv"])
|
| 216 |
+
|
| 217 |
+
if file is not None and st.button("Predict Batch"):
|
| 218 |
+
|
| 219 |
+
inputfile = {"file": (file.name, file.getvalue(), "text/csv")}
|
| 220 |
+
response = requests.post(
|
| 221 |
+
"https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenanceForBatch",
|
| 222 |
+
files=inputfile
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
if response.status_code == 200:
|
| 226 |
+
|
| 227 |
+
result = response.json ()
|
| 228 |
+
|
| 229 |
+
resp_status = result.get ("status")
|
| 230 |
+
|
| 231 |
+
if resp_status == "success":
|
| 232 |
+
|
| 233 |
+
## Get Sales Prediction Value
|
| 234 |
+
predictionS_from_backend = result.get ("predictions") # Extract only the value
|
| 235 |
+
|
| 236 |
+
# convert dict to dataframe for better display
|
| 237 |
+
result_df = pd.DataFrame(list(predictionS_from_backend.items()))
|
| 238 |
+
st.dataframe (result_df)
|
| 239 |
+
|
| 240 |
+
# generate output string
|
| 241 |
+
if prediction_from_backend == 1:
|
| 242 |
+
resultstr = "Engine **likely** needs maintenance."
|
| 243 |
+
else:
|
| 244 |
+
resultstr = "Engine does not need any maintenance"
|
| 245 |
+
|
| 246 |
+
st.success(resultstr)
|
| 247 |
+
|
| 248 |
+
else:
|
| 249 |
+
|
| 250 |
+
error_str = result.get ("message")
|
| 251 |
+
|
| 252 |
+
st.error(error_str)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
elif response.status_code == 400 or response.status_code == 500: # known errors
|
| 256 |
+
|
| 257 |
+
## get result as json
|
| 258 |
+
result = response.json ()
|
| 259 |
+
|
| 260 |
+
error_str = result.get ("message")
|
| 261 |
+
st.error (f"Error processing request- Status Code : {response.status_code}, error : {error_str}")
|
| 262 |
+
|
| 263 |
+
else:
|
| 264 |
+
st.error (f"Error processing request- Status Code : {response.status_code}")
|