import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load the trained model model = tf.keras.models.load_model('tato.h5') # Define class labels (update with your dataset's class names) class_labels = ['Late Blight', 'Early Blight', 'Healthy'] # Define a prediction function def predict(image): # Resize and preprocess the image image = image.resize((224, 224)) # Resize to match model input size image_array = np.array(image) / 255.0 # Normalize the image image_array = np.expand_dims(image_array, axis=0) # Add batch dimension # Make predictions predictions = model.predict(image_array) predicted_class = class_labels[np.argmax(predictions)] # Map prediction to class label confidence = np.max(predictions) # Get the highest confidence score return f"Predicted Class: {predicted_class}" #with confidence {confidence:.2f}" # Create a Gradio interface interface = gr.Interface( theme="Subh775/orchid_candy", fn=predict, # The prediction function inputs=gr.Image(type="pil"), # Input type (image as PIL object) outputs="text", # Output type (text) title="Plant Disease Classifier", description="Upload an image of a potato plant leaf to identify its condition (Early_blight, Late_blight, Healthy)" ) # Launch the interface interface.launch()