|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
import keras as keras |
|
|
|
|
|
model = tf.keras.models.load_model('pokemon_classifier_model.keras') |
|
|
|
|
|
class_names = ['Gengar', 'Pikachu', 'Scyther'] |
|
|
|
def classify_image(image): |
|
|
|
if isinstance(image, np.ndarray): |
|
image = Image.fromarray(image.astype('uint8'), 'RGB') |
|
|
|
|
|
image = np.resize(image, (224, 224, 3)) |
|
|
|
image = image / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
predictions = model.predict(image) |
|
predicted_class = class_names[np.argmax(predictions)] |
|
confidence = np.max(predictions) |
|
|
|
return {predicted_class: float(confidence)} |
|
|
|
image_input = gr.Image() |
|
label = gr.Label(num_top_classes=3) |
|
|
|
interface = gr.Interface( |
|
fn=classify_image, |
|
inputs=image_input, |
|
outputs=label, |
|
title='Pokémon Classifier', |
|
description='Upload an image of Pikachu, Gengar, or Scyther, and the classifier will tell you which Pokémon it is, along with the confidence level of the prediction.' |
|
) |
|
|
|
interface.launch() |