Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
import tensorflow as tf #version 2.13.0
|
4 |
+
import keras #version
|
5 |
+
import numpy as np
|
6 |
+
import cv2
|
7 |
+
import tensorflow as tf
|
8 |
+
import h5py
|
9 |
+
def sepia(img):
|
10 |
+
label_disease = {
|
11 |
+
0 : 'Apple___Apple_scab',
|
12 |
+
1 : 'Apple___Black_rot',
|
13 |
+
2 : 'Apple___Cedar_apple_rust',
|
14 |
+
3 : 'Apple___healthy',
|
15 |
+
4 : 'Background_without_leaves',
|
16 |
+
5 : 'Blueberry___healthy',
|
17 |
+
6 : 'Cherry___Powdery_mildew',
|
18 |
+
7 : 'Cherry___healthy',
|
19 |
+
8 : 'Corn___Cercospora_leaf_spot_Gray_leaf_spot',
|
20 |
+
9 : 'Corn___Common_rust',
|
21 |
+
10: 'Corn___Northern_Leaf_Blight',
|
22 |
+
11: 'Corn___healthy',
|
23 |
+
12: 'Grape___Black_rot',
|
24 |
+
13: 'Grape___Esca_(Black_Measles)',
|
25 |
+
14: 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)',
|
26 |
+
15: 'Grape___healthy',
|
27 |
+
16: 'Orange___Haunglongbing_Citrus_greening',
|
28 |
+
17: 'Peach___Bacterial_spot',
|
29 |
+
18: 'Peach___healthy',
|
30 |
+
19: 'Pepper_bell___Bacterial_spot',
|
31 |
+
20: 'Pepper_bell___healthy',
|
32 |
+
21: 'Potato___Early_blight',
|
33 |
+
22: 'Potato___Late_blight',
|
34 |
+
23: 'Potato___healthy',
|
35 |
+
24: 'Raspberry___healthy',
|
36 |
+
25: 'Soybean___healthy',
|
37 |
+
26: 'Squash___Powdery_mildew',
|
38 |
+
27: 'Strawberry___Leaf_scorch',
|
39 |
+
28: 'Strawberry___healthy',
|
40 |
+
29: 'Tomato___Bacterial_spot',
|
41 |
+
30: 'Tomato___Early_blight',
|
42 |
+
31: 'Tomato___Late_blight',
|
43 |
+
32: 'Tomato___Leaf_Mold',
|
44 |
+
33: 'Tomato___Septoria_leaf_spot',
|
45 |
+
34: 'Tomato___Spider_mites_Two-,spotted_spider_mite',
|
46 |
+
35: 'Tomato___Target_Spot',
|
47 |
+
36: 'Tomato___Tomato_Yellow_Leaf_Curl_Virus',
|
48 |
+
37: 'Tomato___Tomato_mosaic_virus',
|
49 |
+
38: 'Tomato___healthy',
|
50 |
+
}
|
51 |
+
plant_label_disease={
|
52 |
+
"apple":[0,1,2,3],
|
53 |
+
"background_without_leaves":[4],
|
54 |
+
"blueberry" : [5],
|
55 |
+
"cherry" : [6,7],
|
56 |
+
"corn" : [8,9,10,11],
|
57 |
+
"grape" : [12,13,14,15],
|
58 |
+
"orange" : [16] ,
|
59 |
+
"peach" : [17,18],
|
60 |
+
"pepper" : [19,20],
|
61 |
+
"potato" : [21,22,23],
|
62 |
+
"raspberry" : [24],
|
63 |
+
"soybean" : [25],
|
64 |
+
"squash" : [26],
|
65 |
+
"strawberry" : [27,28],
|
66 |
+
"tomato" : [29,30,31,32,33,34,35,36,37,38]
|
67 |
+
}
|
68 |
+
HEIGHT = 256
|
69 |
+
WIDTH = 256
|
70 |
+
dnn_model = keras.models.load_model('untrained_model.h5',compile=False)
|
71 |
+
weights_path = 'keras_savedmodel_weights.h5'
|
72 |
+
dnn_model.load_weights(weights_path)
|
73 |
+
# dnn_model = tf.saved_model.load(model_path)
|
74 |
+
|
75 |
+
process_img = cv2.resize(img, (HEIGHT, WIDTH),interpolation = cv2.INTER_LINEAR)
|
76 |
+
process_img = process_img/(255)
|
77 |
+
process_img = np.expand_dims(process_img, axis=0)
|
78 |
+
|
79 |
+
|
80 |
+
y_pred = dnn_model.predict(process_img)
|
81 |
+
print("y pred",y_pred)
|
82 |
+
indx = np.argmax(y_pred)
|
83 |
+
print(label_disease[indx])
|
84 |
+
return label_disease[indx]
|
85 |
+
|
86 |
+
demo = gr.Interface(sepia, gr.Image(), "text")
|
87 |
+
demo.launch(share=True)
|