KabeerAmjad commited on
Commit
e6daf1b
·
verified ·
1 Parent(s): 3e8dce3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
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
- predicted_class = labels[str(predicted_idx.item())]
84
- print(f"Predicted class index: {predicted_idx.item()}")
85
- print(f"Predicted class: {predicted_class}")
 
 
 
 
 
 
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