Spaces:
Sleeping
Sleeping
Commit
·
7735f05
1
Parent(s):
d7e6465
Update app.py
Browse files
app.py
CHANGED
@@ -64,25 +64,37 @@ def make_prediction(image, taxonomic_level):
|
|
64 |
# Get the top 5 predictions
|
65 |
top_indices = np.argsort(aggregated_predictions[0])[-5:][::-1]
|
66 |
|
67 |
-
# Get predicted class
|
68 |
predicted_class_index = np.argmax(aggregated_predictions)
|
69 |
predicted_class_name = aggregated_class_labels[predicted_class_index]
|
70 |
-
predicted_common_name = taxo_df[taxo_df[taxonomic_level] == predicted_class_name]['common_name'].values[0]
|
71 |
-
confidence = aggregated_predictions[0][predicted_class_index] * 100 # Confidence of the predicted class
|
72 |
|
73 |
-
#
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
output_text += "<h4 style='font-weight: bold; font-size: 1.2em;'>Top 5 Predictions:</h4>"
|
76 |
|
77 |
for i in top_indices:
|
78 |
class_name = aggregated_class_labels[i]
|
79 |
-
common_name = taxo_df[taxo_df[taxonomic_level] == class_name]['common_name'].values[0]
|
80 |
-
confidence_percentage = aggregated_predictions[0][i] * 100
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
return output_text
|
87 |
|
88 |
# Define the Gradio interface
|
|
|
64 |
# Get the top 5 predictions
|
65 |
top_indices = np.argsort(aggregated_predictions[0])[-5:][::-1]
|
66 |
|
67 |
+
# Get predicted class for the top prediction
|
68 |
predicted_class_index = np.argmax(aggregated_predictions)
|
69 |
predicted_class_name = aggregated_class_labels[predicted_class_index]
|
|
|
|
|
70 |
|
71 |
+
# Check if common name should be displayed (only at species level)
|
72 |
+
if taxonomic_level == "species":
|
73 |
+
predicted_common_name = taxo_df[taxo_df[taxonomic_level] == predicted_class_name]['common_name'].values[0]
|
74 |
+
output_text = f"<h1 style='font-weight: bold;'><span style='font-style: italic;'>{predicted_class_name}</span> ({predicted_common_name})</h1>"
|
75 |
+
else:
|
76 |
+
output_text = f"<h1 style='font-weight: bold;'>{predicted_class_name}</h1>"
|
77 |
+
|
78 |
+
# Add the top 5 predictions
|
79 |
output_text += "<h4 style='font-weight: bold; font-size: 1.2em;'>Top 5 Predictions:</h4>"
|
80 |
|
81 |
for i in top_indices:
|
82 |
class_name = aggregated_class_labels[i]
|
|
|
|
|
83 |
|
84 |
+
if taxonomic_level == "species":
|
85 |
+
# Display common names only at species level and make it italic
|
86 |
+
common_name = taxo_df[taxo_df[taxonomic_level] == class_name]['common_name'].values[0]
|
87 |
+
confidence_percentage = aggregated_predictions[0][i] * 100
|
88 |
+
output_text += f"<div style='display: flex; justify-content: space-between;'>" \
|
89 |
+
f"<span style='font-style: italic;'>{class_name}</span> (<span>{common_name}</span>)" \
|
90 |
+
f"<span style='margin-left: auto;'>{confidence_percentage:.2f}%</span></div>"
|
91 |
+
else:
|
92 |
+
# No common names at higher taxonomic levels
|
93 |
+
confidence_percentage = aggregated_predictions[0][i] * 100
|
94 |
+
output_text += f"<div style='display: flex; justify-content: space-between;'>" \
|
95 |
+
f"<span>{class_name}</span>" \
|
96 |
+
f"<span style='margin-left: auto;'>{confidence_percentage:.2f}%</span></div>"
|
97 |
+
|
98 |
return output_text
|
99 |
|
100 |
# Define the Gradio interface
|