bugfix
Browse files- .gitignore +2 -1
- app.py +13 -11
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
pokemon_classifier_model.keras
|
| 2 |
-
main.ipynb
|
|
|
|
|
|
| 1 |
pokemon_classifier_model.keras
|
| 2 |
+
main.ipynb
|
| 3 |
+
newvenv/*
|
app.py
CHANGED
|
@@ -4,25 +4,27 @@ from PIL import Image
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
model_path = "pokemon_classifier_model.keras"
|
| 7 |
-
|
| 8 |
model = tf.keras.models.load_model(model_path)
|
| 9 |
|
| 10 |
-
|
| 11 |
def predict_image(img):
|
| 12 |
-
img = img.resize((224, 224))
|
| 13 |
img = np.array(img)
|
| 14 |
img = img / 255.0
|
| 15 |
img = np.expand_dims(img, axis=0)
|
| 16 |
|
| 17 |
-
prediction = model.predict(img)
|
| 18 |
-
labels = ['Pikachu', 'Sandshrew', 'Squirtle']
|
| 19 |
return {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
|
| 20 |
|
| 21 |
-
iface = gr.Interface(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
iface.launch()
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
model_path = "pokemon_classifier_model.keras"
|
|
|
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
| 8 |
|
|
|
|
| 9 |
def predict_image(img):
|
| 10 |
+
img = img.resize((224, 224)) # Continue to resize the image as your model expects 224x224
|
| 11 |
img = np.array(img)
|
| 12 |
img = img / 255.0
|
| 13 |
img = np.expand_dims(img, axis=0)
|
| 14 |
|
| 15 |
+
prediction = model.predict(img)
|
| 16 |
+
labels = ['Pikachu', 'Sandshrew', 'Squirtle']
|
| 17 |
return {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
|
| 18 |
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=predict_image,
|
| 21 |
+
inputs=gr.components.Image(), # Corrected usage without the 'shape' parameter
|
| 22 |
+
outputs=gr.components.Label(num_top_classes=3),
|
| 23 |
+
title="Pokémon Classifier",
|
| 24 |
+
examples=["images/pikachu.png", "images/squirtle.png", "images/sandshrew.png"],
|
| 25 |
+
description="Upload an image of Pikachu, Sandshrew, or Squirtle and the classifier will predict which one it is."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
|
| 30 |
iface.launch()
|