|
import gradio as gr |
|
import numpy as np |
|
import cv2 |
|
import tensorflow as tf |
|
from tensorflow.keras.preprocessing.image import ImageDataGenerator |
|
|
|
|
|
model = tf.keras.models.load_model('guava_disease_cnn.h5') |
|
|
|
|
|
|
|
test_datagen = ImageDataGenerator(rescale=1./255) |
|
|
|
|
|
class_names = ['0.Anthracnose', '1.Fruit Fly', '2.Healthy Guava'] |
|
|
|
|
|
def classify_image(image): |
|
""" |
|
Process and classify the input image. |
|
Args: |
|
image: Input image in PIL format. |
|
|
|
Returns: |
|
Predicted class label. |
|
""" |
|
|
|
opencv_image = np.array(image) |
|
|
|
img = cv2.resize(opencv_image, (150, 150)) |
|
img = np.expand_dims(img, axis=0).astype('float32') |
|
img = test_datagen.standardize(img) |
|
|
|
predictions = model.predict(img) |
|
predicted_class = class_names[np.argmax(predictions)] |
|
return predicted_class |
|
|
|
|
|
interface = gr.Interface( |
|
fn=classify_image, |
|
inputs=gr.Image(type="pil", label="Upload an image"), |
|
outputs=gr.Textbox(label="Predicted Disease"), |
|
title="Guava Fruit Disease Classification", |
|
description=( |
|
"This app classifies diseases in Guava fruits using deep learning. " |
|
"Upload an image of a papaya to get started." |
|
), |
|
|
|
allow_flagging="never", |
|
) |
|
|
|
|
|
interface.launch() |
|
|