Upload folder using huggingface_hub
Browse files- app.py +36 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
from tensorflow.keras.applications.mobilenet_v3 import preprocess_input
|
| 6 |
+
|
| 7 |
+
MODEL_PATH = "best_model_normal.keras"
|
| 8 |
+
CLASS_NAMES = [
|
| 9 |
+
"Leaf_Algal",
|
| 10 |
+
"Leaf_Blight",
|
| 11 |
+
"Leaf_Colletotrichum",
|
| 12 |
+
"Leaf_Healthy",
|
| 13 |
+
"Leaf_Phomopsis",
|
| 14 |
+
"Leaf_Rhizoctonia",
|
| 15 |
+
]
|
| 16 |
+
IMG_SIZE = (224, 224)
|
| 17 |
+
|
| 18 |
+
model = tf.keras.models.load_model(MODEL_PATH)
|
| 19 |
+
|
| 20 |
+
def predict(img):
|
| 21 |
+
# img: numpy array HxWx3 (uint8)
|
| 22 |
+
x = tf.image.resize(img, IMG_SIZE)
|
| 23 |
+
x = tf.cast(x, tf.float32)
|
| 24 |
+
x = preprocess_input(x) # pipeline train
|
| 25 |
+
x = tf.expand_dims(x, 0) # (1,224,224,3)
|
| 26 |
+
|
| 27 |
+
prob = model.predict(x, verbose=0)[0]
|
| 28 |
+
return {CLASS_NAMES[i]: float(prob[i]) for i in range(len(CLASS_NAMES))}
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=predict,
|
| 32 |
+
inputs=gr.Image(type="numpy", label="Upload A Durian Leaf"),
|
| 33 |
+
outputs=gr.Label(num_top_classes=3, label="Result"),
|
| 34 |
+
title="Durian Leaf Disease Classification",
|
| 35 |
+
)
|
| 36 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|
| 3 |
+
tensorflow==2.18.0
|