KI-A / app.py
fetaiedi's picture
Upload app.py
6086bf9 verified
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
# Load the Pokémon classifier model
model_path = "pokemon_classifier_finetuned.keras"
model = tf.keras.models.load_model(model_path)
labels = ['Dodrio', 'Arbok', 'Gengar']
# Define function for Pokémon classification
def preprocess_image(image):
# Preprocess image
image = Image.fromarray(image.astype('uint8'))
image = image.resize((224, 224))
image = np.array(image)
image = image / 255.0 # Normalize pixel values
return image
# Prediction
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
# Create Gradio interface
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()