import gradio as gr import numpy as np from tensorflow.keras.preprocessing import image from tensorflow.keras.models import load_model from PIL import Image # Load model model = load_model("plant_disease_model.h5") # You must include this file in your repo IMG_SIZE = (224, 224) class_names = ['Apple___Black_rot', 'Tomato___Early_blight', 'Potato___Late_blight'] # Update this to match your model # Prediction function def predict_plant_disease(img): img = img.resize(IMG_SIZE) img_array = image.img_to_array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) predictions = model.predict(img_array) index = np.argmax(predictions) confidence = float(predictions[0][index]) disease_name = class_names[index] confidence_text = f"{confidence:.2%}" confidence_value = round(confidence, 2) return disease_name, confidence_value, confidence_text # Gradio UI with gr.Blocks(css=".green-btn button {background-color: #2e7d32 !important; color: white;}") as demo: gr.Markdown("