|
import gradio as gr |
|
import tensorflow as tf |
|
import cv2 |
|
import numpy as np |
|
|
|
def classify_image(image): |
|
|
|
image = cv2.resize(image, (100, 100)) |
|
|
|
|
|
image = image / 255.0 |
|
|
|
|
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
|
|
label = classes[np.argmax(prediction[0])] |
|
return label |
|
|
|
|
|
model = tf.keras.models.load_model('./my_model.h5') |
|
|
|
|
|
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' |
|
} |
|
|
|
|
|
input_interface = gr.Image() |
|
output_interface = gr.Textbox() |
|
|
|
|
|
gr.Interface(fn=classify_image, inputs=input_interface, outputs=output_interface).launch() |
|
|