import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Klassennamen, sollten Ihrem Dataset entsprechen class_names = ['Apple__black_rot', 'Apple__healthy', 'Apple__rust', 'Apple__scab'] def predict_figure(uploaded_file): if uploaded_file is None: return "No file uploaded.", None, "No prediction" model = tf.keras.models.load_model('apple_classification.keras') # Load the image from the file path with Image.open(uploaded_file).convert('RGB') as img: img = img.resize((150, 150)) img_array = np.array(img) prediction = model.predict(np.expand_dims(img_array, axis=0)) # Identify the most confident prediction confidences = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))} return img, confidences # Define example images examples = [ ["images/Apple__black_rot.JPG"], ["images/Apple__healthy.JPG"], ["images/Apple__rust.JPG"], ["images/Apple__scab.JPG"] ] # Define the Gradio interface iface = gr.Interface( fn=predict_figure, # Function to process the input inputs=gr.File(label="Upload File"), # File upload widget outputs=["image", "text"], # Output types for image and text title="Leaf Disease Classifier", # Title of the interface description="Upload a picture of a Apple Leaf to see condition health it is and the model's confidence level.", # Description of the interface examples=examples # Example images ) iface.launch()