abdulmatinomotoso commited on
Commit
7a7f340
1 Parent(s): 1e7fbda

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -0
app.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from tensorflow import keras
6
+ import matplotlib.pyplot as plt
7
+ import tensorflow_hub as hub
8
+
9
+ hide_streamlit_style = """
10
+ <style>
11
+ #MainMenu {visibility: hidden;}
12
+ footer {visibility: hidden;}
13
+ </style>
14
+ """
15
+
16
+ st.markdown(hide_streamlit_style, unsafe_allow_html = True)
17
+
18
+ st.title('Plant Disease Prediction')
19
+ st.write("This model is capable of predicting 38 different classes of plant diseases")
20
+
21
+ def main() :
22
+ file_uploaded = st.file_uploader('Choose an image...', type = 'jpg')
23
+ if file_uploaded is not None :
24
+ image = Image.open(file_uploaded)
25
+ st.write("Uploaded Image.")
26
+ figure = plt.figure()
27
+ plt.imshow(image)
28
+ plt.axis('off')
29
+ st.pyplot(figure)
30
+ result, confidence = predict_class(image)
31
+ st.write('Prediction : {}'.format(result))
32
+ st.write('Confidence : {}%'.format(confidence))
33
+
34
+ def predict_class(image) :
35
+ with st.spinner('Loading Model...'):
36
+ classifier_model = keras.models.load_model(r'final1_model.h5', compile = False)
37
+
38
+ shape = ((255,255,3))
39
+ model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)]) # ye bhi kaam kar raha he
40
+ test_image = image.resize((255, 255))
41
+ test_image = keras.preprocessing.image.img_to_array(test_image)
42
+ test_image /= 255.0
43
+ test_image = np.expand_dims(test_image, axis = 0)
44
+ class_name = ["Apple___Apple_scab","Apple___Black_rot",
45
+ "Apple___Cedar_apple_rust","Apple___healthy",
46
+ "Blueberry___healthy",
47
+ "Cherry_(including_sour)___Powdery_mildew",
48
+ "Cherry___healthy",
49
+ "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot",
50
+ "Corn_(maize)___Common_rust_",
51
+ "Corn_(maize)___Northern_Leaf_Blight",
52
+ "Corn_(maize)___healthy","Grape___Black_rot",
53
+ "Grape___Esca_(Black_Measles)",
54
+ "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)",
55
+ "Grape___healthy",
56
+ "Orange___Haunglongbing_(Citrus_greening)",
57
+ "Peach___Bacterial_spot",
58
+ "Peach___healthy",
59
+ "Pepper__bell___Bacterial_spot",
60
+ "Pepper,_bell___healthy",
61
+ "Potato___Early_blight",
62
+ "Potato___Late_blight",
63
+ "Potato___healthy",
64
+ "Raspberry___healthy",
65
+ "Soybean___healthy",
66
+ "Squash___Powdery_mildew",
67
+ "Strawberry___Leaf_scorch",
68
+ "Strawberry___healthy",
69
+ "Tomato___Bacterial_spot",
70
+ "Tomato___Early_blight",
71
+ "Tomato___Late_blight",
72
+ "Tomato___Leaf_Mold",
73
+ "Tomato___Septoria_leaf_spot",
74
+ "Tomato___Spider_mites Two-spotted_spider_mite",
75
+ "Tomato___Target_Spot",
76
+ "Tomato___Tomato_Yellow_Leaf_Curl_Virus",
77
+ "Tomato___Tomato_mosaic_virus",
78
+ "Tomato___healthy"]
79
+ prediction = model.predict_generator(test_image)
80
+ confidence = round(100 * (np.max(prediction[0])), 2)
81
+ final_pred = class_name[np.argmax(prediction)]
82
+ return final_pred, confidence
83
+
84
+ footer = """
85
+ <style>
86
+ a:link , a:visited{
87
+ color: white;
88
+ background-color: transparent;
89
+ text-decoration: None;
90
+ }
91
+
92
+ a:hover, a:active {
93
+ color: red;
94
+ background-color: transparent;
95
+ text-decoration: None;
96
+ }
97
+
98
+ .footer {
99
+ position: fixed;
100
+ left: 0;
101
+ bottom: 0;
102
+ width: 100%;
103
+ background-color: transparent;
104
+ color: black;
105
+ text-align: center;
106
+ }
107
+
108
+ <div class="footer">
109
+ <p align="center"> Developed with ❤ by Mato</p>
110
+ </div>
111
+ </style>
112
+ """
113
+ st.markdown(footer, unsafe_allow_html = True)
114
+ if __name__ == "__main__":
115
+ main()