|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
from PIL import Image |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model('Task_Pokemon.keras') |
|
|
|
|
|
|
|
|
class_names = ['Aerodactyl', 'Charizard', 'Victreebel'] |
|
|
|
|
|
def classify_image(image): |
|
|
img = image.resize((160, 160)) |
|
|
img_array = tf.keras.preprocessing.image.img_to_array(img) |
|
|
img_array = tf.expand_dims(img_array, 0) |
|
|
predictions = model.predict(img_array) |
|
|
predicted_class = class_names[np.argmax(predictions[0])] |
|
|
confidence = np.max(predictions[0]) |
|
|
return predicted_class, confidence |
|
|
|
|
|
image_input = gr.inputs.Image() |
|
|
label = gr.outputs.Label(num_top_classes=3) |
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=classify_image, |
|
|
inputs=image_input, |
|
|
outputs=label, |
|
|
title='Pokémon Klassifizierer', |
|
|
description='Lade ein Bild von Aerodactyl, Charizard oder Victreebel hoch und der Klassifizierer wird dir mitteilen, um welches Pokémon es sich handelt, sowie das Vertrauensniveau der Vorhersage.' |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|