Init app and model
Browse files- app.py +75 -0
- plant_badr_model.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 plant disease as a demo")
|
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'plant_badr_model.h5', compile = False)
|
37 |
+
|
38 |
+
shape = ((200,200,3))
|
39 |
+
model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)]) # ye bhi kaam kar raha he
|
40 |
+
test_image = image.resize((200, 200))
|
41 |
+
test_image = keras.preprocessing.image.img_to_array(test_image)
|
42 |
+
test_image /= 256.0
|
43 |
+
test_image = np.expand_dims(test_image, axis = 0)
|
44 |
+
class_name = list(range(0, 37))
|
45 |
+
prediction = model.predict_generator(test_image)
|
46 |
+
confidence = round(100 * (np.max(prediction[0])), 2)
|
47 |
+
final_pred = class_name[np.argmax(prediction)]
|
48 |
+
return final_pred, confidence
|
49 |
+
|
50 |
+
footer = """
|
51 |
+
<style>
|
52 |
+
a:link , a:visited{
|
53 |
+
color: white;
|
54 |
+
background-color: transparent;
|
55 |
+
text-decoration: None;
|
56 |
+
}
|
57 |
+
a:hover, a:active {
|
58 |
+
color: red;
|
59 |
+
background-color: transparent;
|
60 |
+
text-decoration: None;
|
61 |
+
}
|
62 |
+
.footer {
|
63 |
+
position: fixed;
|
64 |
+
left: 0;
|
65 |
+
bottom: 0;
|
66 |
+
width: 100%;
|
67 |
+
background-color: transparent;
|
68 |
+
color: black;
|
69 |
+
text-align: center;
|
70 |
+
}
|
71 |
+
</style>
|
72 |
+
"""
|
73 |
+
st.markdown(footer, unsafe_allow_html = True)
|
74 |
+
if __name__ == "__main__":
|
75 |
+
main()
|
plant_badr_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:884363935c77eb7074fde23ffaa23022d88bb2c2f834cbca3fee1ad27609dfcd
|
3 |
+
size 3061008
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
numpy
|
3 |
+
pillow
|
4 |
+
tensorflow_hub
|