Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,13 +40,31 @@ def on_predict(row_label):
|
|
| 40 |
idx = parse_index(row_label)
|
| 41 |
row = df.iloc[idx][feature_cols]
|
| 42 |
X_row = row.astype(float).values.reshape(1, -1)
|
|
|
|
|
|
|
| 43 |
pred = model.predict(X_row)[0]
|
| 44 |
pred_rounded = float(np.round(pred, 3))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
features_md = "### Input Features\n\n" + row.to_frame().to_markdown()
|
| 46 |
-
result_md =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return "✅ Prediction complete", features_md, result_md
|
| 48 |
|
| 49 |
|
|
|
|
| 50 |
row_choices = [make_row_label(i) for i in range(len(df))]
|
| 51 |
|
| 52 |
with gr.Blocks(css="""
|
|
|
|
| 40 |
idx = parse_index(row_label)
|
| 41 |
row = df.iloc[idx][feature_cols]
|
| 42 |
X_row = row.astype(float).values.reshape(1, -1)
|
| 43 |
+
|
| 44 |
+
# Prediction
|
| 45 |
pred = model.predict(X_row)[0]
|
| 46 |
pred_rounded = float(np.round(pred, 3))
|
| 47 |
+
|
| 48 |
+
# Ground truth
|
| 49 |
+
actual = float(df.iloc[idx]["Yield_g_per_pot"])
|
| 50 |
+
|
| 51 |
+
# Error (always positive)
|
| 52 |
+
error = abs(pred_rounded - actual)
|
| 53 |
+
error_rounded = float(np.round(error, 3))
|
| 54 |
+
|
| 55 |
+
# Markdown display
|
| 56 |
features_md = "### Input Features\n\n" + row.to_frame().to_markdown()
|
| 57 |
+
result_md = (
|
| 58 |
+
f"### Results\n\n"
|
| 59 |
+
f"**Predicted Yield (g per pot):** {pred_rounded}\n\n"
|
| 60 |
+
f"**Actual Yield (Ground Truth):** {actual}\n\n"
|
| 61 |
+
f"**Absolute Error:** {error_rounded}"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
return "✅ Prediction complete", features_md, result_md
|
| 65 |
|
| 66 |
|
| 67 |
+
|
| 68 |
row_choices = [make_row_label(i) for i in range(len(df))]
|
| 69 |
|
| 70 |
with gr.Blocks(css="""
|