Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,9 +80,15 @@ def predict(image):
|
|
| 80 |
|
| 81 |
# Get the predicted class with the highest score
|
| 82 |
_, predicted_idx = torch.max(output, 1)
|
| 83 |
-
|
| 84 |
-
print(f"Predicted class index: {predicted_idx
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
return f"Predicted class: {predicted_class}"
|
| 88 |
|
|
|
|
| 80 |
|
| 81 |
# Get the predicted class with the highest score
|
| 82 |
_, predicted_idx = torch.max(output, 1)
|
| 83 |
+
predicted_idx = predicted_idx.item()
|
| 84 |
+
print(f"Predicted class index: {predicted_idx}")
|
| 85 |
+
|
| 86 |
+
# Check if the predicted index exists in labels
|
| 87 |
+
if str(predicted_idx) in labels:
|
| 88 |
+
predicted_class = labels[str(predicted_idx)]
|
| 89 |
+
else:
|
| 90 |
+
predicted_class = f"Unknown class index: {predicted_idx}. Please check the label mapping."
|
| 91 |
+
print(predicted_class)
|
| 92 |
|
| 93 |
return f"Predicted class: {predicted_class}"
|
| 94 |
|