|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model = tf.keras.models.load_model('pokemon_classifier_model.keras') |
|
|
|
def predict(image): |
|
img = tf.keras.preprocessing.image.img_to_array(image) |
|
img = tf.keras.preprocessing.image.smart_resize(img, (224, 224)) |
|
img = tf.expand_dims(img, 0) |
|
|
|
pred = model.predict(img) |
|
pred_label = tf.argmax(pred, axis=1).numpy()[0] |
|
pred_class = class_names[pred_label] |
|
confidence = tf.nn.softmax(pred)[0][pred_label] |
|
|
|
print(f"Predicted: {pred_class}, Confidence: {confidence:.4f}") |
|
return pred_class |
|
|
|
|
|
|
|
iface = gr.Interface(fn=predict, inputs=gr.Image(), outputs="text", title="Pokémon Classifier") |
|
|
|
|
|
iface.launch() |