Spaces:
Sleeping
Sleeping
Commit ·
fc41c89
1
Parent(s): b872f48
Backend: Add Base64 support for mobile (/predict_mobile)
Browse files- backend/app.py +13 -1
backend/app.py
CHANGED
|
@@ -102,9 +102,21 @@ def run_inference(image_bytes: bytes) -> PredictionResponse:
|
|
| 102 |
# 4. Generate explanations
|
| 103 |
explain_maps = generate_all_explanations(model, preprocessor, image_tensor, image_bytes)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
return PredictionResponse(
|
| 106 |
predicted_labels=predicted_labels,
|
| 107 |
-
all_predictions=
|
| 108 |
explainability_maps=explain_maps,
|
| 109 |
uncertainty=uncertainty,
|
| 110 |
inference_time_ms=inference_time,
|
|
|
|
| 102 |
# 4. Generate explanations
|
| 103 |
explain_maps = generate_all_explanations(model, preprocessor, image_tensor, image_bytes)
|
| 104 |
|
| 105 |
+
sorted_preds = sorted(all_predictions, key=lambda x: x.confidence, reverse=True)
|
| 106 |
+
|
| 107 |
+
# LOGGING: Print detailed output to console/logs
|
| 108 |
+
print(f"\n--- AMSI-Net Inference Results ---")
|
| 109 |
+
print(f"Predicted Labels: {predicted_labels}")
|
| 110 |
+
print(f"Uncertainty Score: {uncertainty:.6f}")
|
| 111 |
+
print(f"Inference Latency: {inference_time:.2f}ms")
|
| 112 |
+
print(f"Top 5 Predictions:")
|
| 113 |
+
for p in sorted_preds[:5]:
|
| 114 |
+
print(f" - {p.class_label}: {p.confidence:.4f}")
|
| 115 |
+
print(f"----------------------------------\n")
|
| 116 |
+
|
| 117 |
return PredictionResponse(
|
| 118 |
predicted_labels=predicted_labels,
|
| 119 |
+
all_predictions=sorted_preds,
|
| 120 |
explainability_maps=explain_maps,
|
| 121 |
uncertainty=uncertainty,
|
| 122 |
inference_time_ms=inference_time,
|