gassmdav's picture
Update app.py
ee06b6f verified
raw
history blame
1.17 kB
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
# Laden des vortrainierten Pokémon-Modells
model_path = "kia_pokemon_keras_model.h5"
model = tf.keras.models.load_model(model_path)
# Labels für den Pokémon Classifier
labels = [
'Bulbasaur','Charmander','Squirtle'
]
def predict_pokemon(image):
# Predict
predictions = model.predict(image)
prediction = np.argmax(predictions, axis=1)[0]
confidence = np.max(predictions)
# Vorbereiten der Ausgabe
result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}"
return result
# Erstellen der Gradio-Oberfläche
input_image = gr.Image()
output_label = gr.Label()
interface = gr.Interface(fn=predict_pokemon,
inputs=input_image,
outputs=output_label,
examples=["images/bulbasaur.png", "images/charmander.png", "images/squirtle.png"],
title="Pokémon Classifier",
description="Drag and drop an image or select an example below to predict the Pokémon.")
# Interface starten
interface.launch()