Spaces:
Running
Running
import numpy as np | |
import gradio as gr | |
import tensorflow as tf #version 2.13.0 | |
import keras #version | |
import numpy as np | |
import cv2 | |
import tensorflow as tf | |
import h5py | |
def sepia(img): | |
label_disease = { | |
0 : 'Apple___Apple_scab', | |
1 : 'Apple___Black_rot', | |
2 : 'Apple___Cedar_apple_rust', | |
3 : 'Apple___healthy', | |
4 : 'Background_without_leaves', | |
5 : 'Blueberry___healthy', | |
6 : 'Cherry___Powdery_mildew', | |
7 : 'Cherry___healthy', | |
8 : 'Corn___Cercospora_leaf_spot_Gray_leaf_spot', | |
9 : 'Corn___Common_rust', | |
10: 'Corn___Northern_Leaf_Blight', | |
11: 'Corn___healthy', | |
12: 'Grape___Black_rot', | |
13: 'Grape___Esca_(Black_Measles)', | |
14: 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)', | |
15: 'Grape___healthy', | |
16: 'Orange___Haunglongbing_Citrus_greening', | |
17: 'Peach___Bacterial_spot', | |
18: 'Peach___healthy', | |
19: 'Pepper_bell___Bacterial_spot', | |
20: 'Pepper_bell___healthy', | |
21: 'Potato___Early_blight', | |
22: 'Potato___Late_blight', | |
23: 'Potato___healthy', | |
24: 'Raspberry___healthy', | |
25: 'Soybean___healthy', | |
26: 'Squash___Powdery_mildew', | |
27: 'Strawberry___Leaf_scorch', | |
28: 'Strawberry___healthy', | |
29: 'Tomato___Bacterial_spot', | |
30: 'Tomato___Early_blight', | |
31: 'Tomato___Late_blight', | |
32: 'Tomato___Leaf_Mold', | |
33: 'Tomato___Septoria_leaf_spot', | |
34: 'Tomato___Spider_mites_Two-,spotted_spider_mite', | |
35: 'Tomato___Target_Spot', | |
36: 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', | |
37: 'Tomato___Tomato_mosaic_virus', | |
38: 'Tomato___healthy', | |
} | |
plant_label_disease={ | |
"apple":[0,1,2,3], | |
"background_without_leaves":[4], | |
"blueberry" : [5], | |
"cherry" : [6,7], | |
"corn" : [8,9,10,11], | |
"grape" : [12,13,14,15], | |
"orange" : [16] , | |
"peach" : [17,18], | |
"pepper" : [19,20], | |
"potato" : [21,22,23], | |
"raspberry" : [24], | |
"soybean" : [25], | |
"squash" : [26], | |
"strawberry" : [27,28], | |
"tomato" : [29,30,31,32,33,34,35,36,37,38] | |
} | |
HEIGHT = 256 | |
WIDTH = 256 | |
dnn_model = keras.models.load_model('untrained_model.h5',compile=False) | |
weights_path = 'keras_savedmodel_weights.h5' | |
dnn_model.load_weights(weights_path) | |
# dnn_model = tf.saved_model.load(model_path) | |
process_img = cv2.resize(img, (HEIGHT, WIDTH),interpolation = cv2.INTER_LINEAR) | |
process_img = process_img/(255) | |
process_img = np.expand_dims(process_img, axis=0) | |
y_pred = dnn_model.predict(process_img) | |
print("y pred",y_pred) | |
indx = np.argmax(y_pred) | |
print(label_disease[indx]) | |
return label_disease[indx] | |
demo = gr.Interface(sepia, gr.Image(), "text") | |
demo.launch(share=True) | |