Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
from tensorflow.keras.models import load_model | |
from tensorflow.keras.preprocessing import image | |
import tensorflow as tf | |
# Load the saved model | |
model = load_model('acres-ppdc-01.keras') | |
# Define the classes the model was trained on | |
class_labels = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy'] | |
def classify_potato_plant(img): | |
# Preprocess the image for the model | |
img = img.resize((128, 128)) # Resize to the same size the model was trained on | |
img = image.img_to_array(img) | |
img = np.expand_dims(img, axis=0) | |
img = img / 255.0 # Normalize the image | |
# Make the prediction | |
predictions = model.predict(img) | |
predicted_class = np.argmax(predictions[0]) | |
confidence = predictions[0][predicted_class] | |
model_output = "None" | |
if class_labels[predicted_class] == "Potato__Early_blight": | |
model_output = "Early blight" | |
elif class_labels[predicted_class] == "Potato__Late_blight": | |
model_output = "Late blight" | |
elif class_labels[predicted_class] == "Potate__healthy": | |
model_output = "Healthy" | |
return model_output, confidence | |
# Create the Gradio interface | |
interface = gr.Interface( | |
fn=classify_potato_plant, | |
inputs=gr.Image(type="pil"), | |
outputs=[gr.Label(label="Predicted output", num_top_classes=1), gr.Textbox(label="Confidence Score")], | |
title="Acres - PPDC", | |
description="Acres PPDC, is our Potato Plant Disease Classification vision model, capable of accurately classifying potato plant disease, based on a single image." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
interface.launch() |