sailakshmi123 commited on
Commit
2d71b2a
·
verified ·
1 Parent(s): 377bc62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -25,7 +25,7 @@ class_indices = load_labels()
25
  class_labels = list(class_indices.keys())
26
 
27
  # Title
28
- st.title(" Animal Image Classifier")
29
  st.markdown("Upload up to **3 images** to get predictions")
30
 
31
  # File uploader
@@ -55,18 +55,13 @@ if uploaded_files:
55
 
56
  # Prediction
57
  preds = model.predict(img_array)[0]
58
- top_indices = preds.argsort()[-3:][::-1]
59
- top_labels = [class_labels[i] for i in top_indices]
60
- top_scores = [preds[i] for i in top_indices]
61
 
62
- # Display predictions
63
- st.success(f"Top Prediction: **{top_labels[0].capitalize()}**")
64
- st.markdown("##### Top 3 Predictions:")
65
- for label, score in zip(top_labels, top_scores):
66
- st.write(f"**{label.capitalize()}** — {score:.4f}")
67
 
68
  except UnidentifiedImageError:
69
  st.error("Error: Invalid image file.")
70
  except Exception as e:
71
  st.error(f"Unexpected error: {str(e)}")
72
-
 
25
  class_labels = list(class_indices.keys())
26
 
27
  # Title
28
+ st.title("Animal Image Classifier")
29
  st.markdown("Upload up to **3 images** to get predictions")
30
 
31
  # File uploader
 
55
 
56
  # Prediction
57
  preds = model.predict(img_array)[0]
58
+ top_index = np.argmax(preds)
59
+ top_label = class_labels[top_index]
 
60
 
61
+ # Display top prediction only
62
+ st.success(f"Top Prediction: **{top_label.capitalize()}**")
 
 
 
63
 
64
  except UnidentifiedImageError:
65
  st.error("Error: Invalid image file.")
66
  except Exception as e:
67
  st.error(f"Unexpected error: {str(e)}")