Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -231,19 +231,32 @@ if file is not None and st.button("Predict Batch"):
|
|
| 231 |
if resp_status == "success":
|
| 232 |
|
| 233 |
## Get Sales Prediction Value
|
| 234 |
-
|
| 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 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
| 245 |
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
else:
|
| 249 |
|
|
|
|
| 231 |
if resp_status == "success":
|
| 232 |
|
| 233 |
## Get Sales Prediction Value
|
| 234 |
+
predictions_from_backend = result.get ("predictions") # Extract only the value
|
| 235 |
|
|
|
|
|
|
|
| 236 |
st.dataframe (result_df)
|
| 237 |
+
# Convert list → DataFrame
|
| 238 |
+
result_df = pd.DataFrame({
|
| 239 |
+
"Prediction": predictions_from_backend
|
| 240 |
+
})
|
| 241 |
|
| 242 |
+
st.dataframe (result_df)
|
| 243 |
+
|
| 244 |
+
input_df = pd.read_csv(file)
|
| 245 |
+
|
| 246 |
+
# Ensure lengths match
|
| 247 |
+
if len(predictions_from_backend) == len(input_df):
|
| 248 |
|
| 249 |
+
# Add prediction column
|
| 250 |
+
input_df["Prediction"] = predictions_from_backend
|
| 251 |
+
|
| 252 |
+
st.success("Batch prediction completed successfully")
|
| 253 |
+
|
| 254 |
+
# Show combined dataframe
|
| 255 |
+
st.dataframe(input_df, use_container_width=True)
|
| 256 |
+
|
| 257 |
+
else:
|
| 258 |
+
st.error("Prediction count does not match input records")
|
| 259 |
+
|
| 260 |
|
| 261 |
else:
|
| 262 |
|