Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ class_indices = load_labels()
|
|
| 25 |
class_labels = list(class_indices.keys())
|
| 26 |
|
| 27 |
# Title
|
| 28 |
-
st.title("
|
| 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 |
-
|
| 59 |
-
|
| 60 |
-
top_scores = [preds[i] for i in top_indices]
|
| 61 |
|
| 62 |
-
# Display
|
| 63 |
-
st.success(f"Top Prediction: **{
|
| 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)}")
|
|
|