Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,10 @@ def predict_pokemon(image):
|
|
| 27 |
class_names = ['Pikachu', 'Raichu', 'Snorlax']
|
| 28 |
probabilities_dict = {pokemon_class: round(float(probability), 2) for pokemon_class, probability in zip(class_names, probabilities.numpy()[0])}
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Streamlit interface
|
| 33 |
st.title("Pokemon Classification Tool")
|
|
@@ -42,18 +45,15 @@ if uploaded_image is not None:
|
|
| 42 |
st.write("")
|
| 43 |
st.write("Classifying...")
|
| 44 |
|
| 45 |
-
predictions = predict_pokemon(image)
|
| 46 |
|
| 47 |
-
# Display
|
| 48 |
-
st.write("###
|
| 49 |
-
df = pd.DataFrame(predictions.items(), columns=["Pokemon", "Probability"])
|
| 50 |
-
st.dataframe(df)
|
| 51 |
|
| 52 |
-
# Display predictions as a
|
| 53 |
st.write("### Prediction Chart")
|
| 54 |
fig, ax = plt.subplots()
|
| 55 |
-
ax.
|
| 56 |
-
ax.set_xlim(0, 1)
|
| 57 |
-
ax.set_xlabel('Probability')
|
| 58 |
ax.set_title('Prediction Probabilities')
|
| 59 |
-
|
|
|
|
|
|
| 27 |
class_names = ['Pikachu', 'Raichu', 'Snorlax']
|
| 28 |
probabilities_dict = {pokemon_class: round(float(probability), 2) for pokemon_class, probability in zip(class_names, probabilities.numpy()[0])}
|
| 29 |
|
| 30 |
+
# Get the predicted Pokemon
|
| 31 |
+
predicted_pokemon = max(probabilities_dict, key=probabilities_dict.get)
|
| 32 |
+
|
| 33 |
+
return predicted_pokemon, probabilities_dict
|
| 34 |
|
| 35 |
# Streamlit interface
|
| 36 |
st.title("Pokemon Classification Tool")
|
|
|
|
| 45 |
st.write("")
|
| 46 |
st.write("Classifying...")
|
| 47 |
|
| 48 |
+
predicted_pokemon, predictions = predict_pokemon(image)
|
| 49 |
|
| 50 |
+
# Display predicted Pokemon name in bold and large font
|
| 51 |
+
st.write(f"### **Predicted Pokemon: {predicted_pokemon.upper()}**")
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# Display predictions as a pie chart
|
| 54 |
st.write("### Prediction Chart")
|
| 55 |
fig, ax = plt.subplots()
|
| 56 |
+
ax.pie(predictions.values(), labels=predictions.keys(), autopct='%1.1f%%', startangle=90)
|
|
|
|
|
|
|
| 57 |
ax.set_title('Prediction Probabilities')
|
| 58 |
+
ax.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
|
| 59 |
+
st.pyplot(fig)
|