Add app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from tensorflow.keras.models import load_model
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
model = load_model('pokemon_classifier_model.keras')
|
| 7 |
+
|
| 8 |
+
def predict_image(img):
|
| 9 |
+
img = img.resize((224, 224))
|
| 10 |
+
img = np.array(img)
|
| 11 |
+
img = img / 255.0
|
| 12 |
+
img = np.expand_dims(img, axis=0)
|
| 13 |
+
|
| 14 |
+
prediction = model.predict(img)
|
| 15 |
+
labels = ['Pikachu', 'Sandshrew', 'Squirtle']
|
| 16 |
+
return {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
|
| 17 |
+
|
| 18 |
+
iface = gr.Interface(fn=predict_image,
|
| 19 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
| 20 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
| 21 |
+
title="Pokémon Classifier",
|
| 22 |
+
description="Upload an image of Pikachu, Sandshrew, or Squirtle and the classifier will predict which one it is.")
|
| 23 |
+
|
| 24 |
+
iface.launch()
|