File size: 946 Bytes
79bd2b2 5a525dd 79bd2b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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()
|