|
|
|
import gradio as gr
|
|
import numpy as np
|
|
from tensorflow.keras.models import load_model
|
|
from tensorflow.keras.applications.resnet50 import preprocess_input
|
|
from PIL import Image
|
|
|
|
|
|
model = load_model('pokemon-model.keras')
|
|
|
|
|
|
class_labels = ['Bulbasaur', 'Glumanda', 'Pikachu']
|
|
|
|
|
|
def predict_image(img):
|
|
|
|
if not isinstance(img, Image.Image):
|
|
img = Image.fromarray(img)
|
|
|
|
|
|
img = img.resize((224, 224))
|
|
|
|
|
|
img_array = np.array(img)
|
|
|
|
|
|
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
|
|
img_array = preprocess_input(img_array)
|
|
|
|
|
|
prediction = model.predict(img_array)
|
|
|
|
|
|
predicted_index = int(np.argmax(prediction))
|
|
predicted_label = class_labels[predicted_index]
|
|
|
|
return predicted_label
|
|
|
|
|
|
iface = gr.Interface(
|
|
fn=predict_image,
|
|
inputs=gr.Image(image_mode='RGB'),
|
|
outputs='label',
|
|
examples=[['00000015.jpg'], ['20.png'], ['glumanda.jpg'], ['j67j7.png'], ['pikachu.jpg']],
|
|
title="Pokémon Classification",
|
|
description="Upload an image of a Pokémon to classify it using the pre-trained model."
|
|
)
|
|
|
|
|
|
iface.launch(inline=True)
|
|
|
|
|
|
|
|
|
|
print(model.summary())
|
|
|
|
|
|
|
|
|