File size: 1,526 Bytes
e914fdf
 
 
 
 
c3bf961
e914fdf
0f18e7b
e914fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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):
    # Preprocess image
    print(type(image))  # Output the type of the input image for debugging
    image = Image.fromarray(image.astype('uint8'))  # Convert numpy array to PIL image
    image = image.resize((224, 224))  # Resize the image to 224x224
    image = np.array(image)
    image = np.expand_dims(image, axis=0)  # same as image[None, ...]
    
    # 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()