Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Pfad zum gespeicherten Modell | |
| model_path = "pokemon-model_transferlearning.keras" | |
| model = tf.keras.models.load_model(model_path) | |
| # Definieren der Klassennamen | |
| labels = ['Articuno', 'Bulbasaur', 'Charmander'] | |
| # Funktion zur Klassifizierung | |
| def classify_pokemon(image): | |
| if image is None: | |
| return {"Error": "No image uploaded"} | |
| # Bildvorverarbeitung | |
| image = Image.fromarray(image).resize((150, 150)) | |
| image = np.array(image) / 255.0 | |
| image = np.expand_dims(image, axis=0) | |
| # Vorhersage | |
| prediction = model.predict(image) | |
| predicted_class = np.argmax(prediction[0]) | |
| confidence = np.max(prediction[0]) | |
| # Konfidenzwerte | |
| confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} | |
| return confidences, f"Predicted: {labels[predicted_class]}, Confidence: {confidence:.2f}" | |
| # Erstellen einer Gradio-Schnittstelle | |
| iface = gr.Interface( | |
| fn=classify_pokemon, | |
| inputs=gr.Image(), | |
| outputs=["label", "text"], | |
| live=True | |
| ) | |
| # Starten der Schnittstelle | |
| iface.launch() | |