File size: 1,667 Bytes
080e4cc
 
 
 
 
 
 
000e8b7
080e4cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import numpy as np
import cv2
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator

# Load the model
model = tf.keras.models.load_model('model6.h5')

# Preprocessing
test_datagen = ImageDataGenerator(rescale=1./255)

# Class labels
class_names = ['0.Healthy', '1.Anthracnose', '2.Phytophthora Blight', 
               '3.Brown Spot', '4.Black Spot', '5.Others']

# Prediction function
def classify_image(image):
    """
    Process and classify the input image.
    Args:
        image: Input image in PIL format.

    Returns:
        Predicted class label.
    """
    # Convert to numpy array
    opencv_image = np.array(image)
    # Resize and preprocess the image
    img = cv2.resize(opencv_image, (150, 150))
    img = np.expand_dims(img, axis=0).astype('float32')  # Expand dimensions
    img = test_datagen.standardize(img)  # Normalize the image
    # Predict using the model
    predictions = model.predict(img)
    predicted_class = class_names[np.argmax(predictions)]
    return predicted_class

# Gradio Interface
interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil", label="Upload an image"),
    outputs=gr.Textbox(label="Predicted Disease"),
    title="Papaya Fruit Disease Classification",
    description=(
        "This app classifies diseases in papaya fruits using deep learning. "
        "Upload an image of a papaya to get started."
    ),
    examples=[
        ["example_images/healthy.jpg"],
        ["example_images/anthracnose.jpg"],
        ["example_images/brown_spot.jpg"],
    ],
    allow_flagging="never",
)

# Launch the app
interface.launch()