import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load your trained model model = tf.keras.models.load_model("watermelon_cnn_model.h5") # Ensure this matches the name in your repo # Define the prediction function def predict(image): # Resize the input image to match the model's input size image = image.resize((128, 128)) # Adjust dimensions to match your model image = np.array(image) / 255.0 # Normalize pixel values image = np.expand_dims(image, axis=0) # Add batch dimension prediction = model.predict(image) # Replace the below with your actual class names class_names = ["Anthracnose", "Downy Mildew", "Mosaic Virus", "Healthy"] return {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))} # Create a Gradio interface interface = gr.Interface( fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label() ) interface.launch()