Spaces:
Runtime error
Runtime error
| 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() | |