Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
import tensorflow as tf
|
7 |
+
from tensorflow.keras.layers import *
|
8 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
9 |
+
|
10 |
+
|
11 |
+
def classify_grapevine_leaves(img):
|
12 |
+
categories = ("Healthy", "Powdery Mildew", "Rust")
|
13 |
+
|
14 |
+
# load keras model
|
15 |
+
model = tf.keras.models.load_model("./keras_model/")
|
16 |
+
# load image
|
17 |
+
# img = tf.keras.preprocessing.image.load_img(img, target_size=(360, 360))
|
18 |
+
# convert image to array
|
19 |
+
img = tf.keras.preprocessing.image.img_to_array(img)
|
20 |
+
# add batch dimension
|
21 |
+
img = tf.expand_dims(img, axis=0)
|
22 |
+
# predict
|
23 |
+
prediction = model.predict(img)
|
24 |
+
# get label
|
25 |
+
print(np.argmax(prediction, axis=1))
|
26 |
+
label = categories[prediction.argmax()]
|
27 |
+
# get confidence
|
28 |
+
conf = prediction[0][prediction.argmax()]
|
29 |
+
# return label and confidence
|
30 |
+
return dict(zip(categories, map(float, prediction[0])))
|
31 |
+
|
32 |
+
|
33 |
+
exemples = [
|
34 |
+
"./exemples/healthy.jpg",
|
35 |
+
"./exemples/powdery.jpg",
|
36 |
+
"./exemples/rust.jpg",
|
37 |
+
]
|
38 |
+
|
39 |
+
image = gr.inputs.Image(shape=(360, 360))
|
40 |
+
label = gr.outputs.Label()
|
41 |
+
app = gr.Interface(
|
42 |
+
fn=classify_grapevine_leaves, inputs=image, outputs=label, examples=exemples
|
43 |
+
)
|
44 |
+
app.launch(inline=False)
|