Spaces:
Runtime error
Runtime error
File size: 1,155 Bytes
387ddaf b8e7728 387ddaf b8e7728 387ddaf b8e7728 387ddaf b8e7728 387ddaf b8e7728 387ddaf |
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 |
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
# Modell laden mit Fehlerbehandlung
try:
model = tf.keras.models.load_model('pokemon_classifier_model.keras')
except Exception as e:
print(f"Fehler beim Laden des Modells: {e}")
# Klassenlabels
class_names = ['Bisasam', 'Schiggy', 'Glumanda']
# Vorhersagefunktion
def predict(img):
try:
img = img.resize((224, 224))
img_array = np.array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = tf.keras.applications.vgg16.preprocess_input(img_array)
predictions = model.predict(img_array)
score = tf.nn.softmax(predictions[0])
return {class_names[i]: float(score[i]) for i in range(3)}
except Exception as e:
return {"Fehler": str(e)}
# Gradio Interface erstellen
image_input = gr.Image(type='pil')
label_output = gr.Label(num_top_classes=3)
gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
title="Pokémon Classifier",
description="Laden Sie ein Bild hoch, um das Pokémon zu klassifizieren.").launch()
|