import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Laden Sie Ihr angepasstes EfficientNetB0-Modell model_path = "pokemon_classifier_small_effnet.keras" model = tf.keras.models.load_model(model_path) labels = ['Arbok', 'Nidoking', 'Tauros'] # Vorverarbeitungsfunktion für das Bild def preprocess_image(image): image = Image.fromarray(image.astype('uint8')) image = image.resize((224, 224)) image = np.array(image) image = image / 255.0 # Normalisierung return image # Vorhersagefunktion mit postprocess def predict_class(image): image = preprocess_image(image) prediction = model.predict(image[None, ...]) predicted_class = labels[np.argmax(prediction)] confidence = np.round(np.max(prediction) * 100, 2) result = f"Label: {predicted_class}, Confidence: {confidence}%" return result # Gradio-Schnittstelle erstellen input_image = gr.Image() output_text = gr.Textbox(label="Predicted Class and Confidence") interface = gr.Interface(fn=predict_class, inputs=input_image, outputs=output_text, examples=[ ["images/imagesexample_pokemon1.jpeg"], ["images/imagesexample_pokemon2.jpeg"], ["images/imagesexample_pokemon3.jpeg"] ], description="A simple classification model for Pokemon images.") if __name__ == "__main__": interface.launch()