|
|
import gradio as gr |
|
|
import numpy as np |
|
|
import tensorflow as tf |
|
|
from tensorflow.keras.applications.mobilenet_v3 import preprocess_input |
|
|
|
|
|
MODEL_PATH = "best_model_normal.keras" |
|
|
CLASS_NAMES = [ |
|
|
"Leaf_Algal", |
|
|
"Leaf_Blight", |
|
|
"Leaf_Colletotrichum", |
|
|
"Leaf_Healthy", |
|
|
"Leaf_Phomopsis", |
|
|
"Leaf_Rhizoctonia", |
|
|
] |
|
|
IMG_SIZE = (224, 224) |
|
|
|
|
|
model = tf.keras.models.load_model(MODEL_PATH) |
|
|
|
|
|
def predict(img): |
|
|
|
|
|
x = tf.image.resize(img, IMG_SIZE) |
|
|
x = tf.cast(x, tf.float32) |
|
|
x = preprocess_input(x) |
|
|
x = tf.expand_dims(x, 0) |
|
|
|
|
|
prob = model.predict(x, verbose=0)[0] |
|
|
return {CLASS_NAMES[i]: float(prob[i]) for i in range(len(CLASS_NAMES))} |
|
|
|
|
|
|
|
|
sample_images = [ |
|
|
"samples/Leaf_Algal_1.jpg", |
|
|
"samples/Leaf_Blight_103.jpg", |
|
|
"samples/Leaf_Colletotrichum_130.jpg", |
|
|
"samples/Leaf_Healthy_101.jpg", |
|
|
"samples/Leaf_Phomopsis_118.jpg" |
|
|
] |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=predict, |
|
|
inputs=gr.Image(type="numpy", label="Upload A Durian Leaf"), |
|
|
outputs=gr.Label(num_top_classes=3, label="Result"), |
|
|
title="Durian Leaf Disease Classification", |
|
|
examples=sample_images |
|
|
) |
|
|
demo.launch() |