File size: 1,159 Bytes
421347b
 
 
 
 
 
 
a85c7b5
421347b
 
 
 
 
 
 
 
 
 
 
 
 
 
f314512
421347b
 
f314512
421347b
 
 
 
 
 
 
 
 
 
 
 
 
f314512
 
 
421347b
 
 
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
import gradio as gr
import tensorflow as tf
import cv2
import numpy as np

def classify_image(image):
    # Read and resize the image
    image = cv2.resize(image, (100, 100))

    # Normalize the image
    image = image / 255.0

    # Expand dimensions to match the input shape of the model
    image = np.expand_dims(image, axis=0)

    # Perform prediction using the trained model
    prediction = model.predict(image)

    # Get the predicted label
    label = classes[np.argmax(prediction[0])]
    return label

# Load the pre-trained model
model = tf.keras.models.load_model('./my_model.h5')

# Define the class labels
classes = {
    0: 'Bacterial_spot',
    1: 'Early_blight',
    2: 'Late_blight',
    3: 'Leaf_Mold',
    4: 'Septoria_leaf_spot',
    5: 'Spider_mites',
    6: 'Target_Spot',
    7: 'Tomato_Yellow_Leaf_Curl_Virus',
    8: 'Tomato_mosaic_virus',
    9: 'healthy'
}

# Define the input and output interfaces for Gradio v3.x
input_interface = gr.Image()  # Removed 'shape' argument
output_interface = gr.Textbox()

# Create the Gradio interface
gr.Interface(fn=classify_image, inputs=input_interface, outputs=output_interface).launch()