|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model_path = "pokemon_classifier_finetuned.keras" |
|
model = tf.keras.models.load_model(model_path) |
|
|
|
labels = ['Dodrio', 'Arbok', 'Gengar'] |
|
|
|
|
|
def preprocess_image(image): |
|
|
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((224, 224)) |
|
image = np.array(image) |
|
image = image / 255.0 |
|
return image |
|
|
|
|
|
def predict_pokemon(image): |
|
image = preprocess_image(image) |
|
prediction = model.predict(image[None, ...]) |
|
predicted_class = labels[np.argmax(prediction)] |
|
confidence = np.round(np.max(prediction) * 100, 2) |
|
result = f"Label: {predicted_class}, Confidence: {confidence}%" |
|
return result |
|
|
|
|
|
input_image = gr.Image() |
|
output_text = gr.Textbox(label="Pokemon") |
|
interface = gr.Interface(fn=predict_pokemon, |
|
inputs=input_image, |
|
outputs=output_text, |
|
description="A Pokémon classifier using transfer learning and fine-tuning with EfficientNetB0.") |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |