-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
91 lines (76 loc) · 3.48 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import numpy as np
from io import BytesIO
from PIL import Image
import tensorflow as tf
import base64
import cv2
MODEL = tf.keras.models.load_model('./potato_trained_models/1/')
TOMATO_MODEL = tf.keras.models.load_model('./tomato_trained_models/1')
PEEPER_MODEL = tf.keras.models.load_model('./pepper_trained_models/1')
class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
Tomato_classes = ['Tomato_healthy', 'Tomato_Spider_mites_Two_spotted_spider_mite', 'Tomato__Target_Spot', 'Tomato_Septoria_leaf_spot',
'Tomato__Tomato_mosaic_virus', 'Tomato_Leaf_Mold', 'Tomato_Bacterial_spot', 'Tomato_Late_blight',
'Tomato_Early_blight', 'Tomato__Tomato_YellowLeaf__Curl_Virus']
pepper_classes = ['pepper_healthy', 'pepper_bell_bacterial_spot']
st.set_page_config(
layout="wide",
page_title='plant disease detection',
)
st.title("Plant Disease Detection")
st.write("This application is detecting disease in three plants photato, tomato and pepper")
options = ["Select One Plant","Tomato", "Potato", "Pepper"]
# Create a selectbox for the user to choose one option
selected_option = st.selectbox("Select Plant:", options)
# st.write("You selected:", selected_option)
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
def read_file_as_image(data)->np.array:
image = np.array(data)
image = cv2.resize(image, (256,256))
return image
async def potato():
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", width=250)
image = read_file_as_image(image)
image_batch = np.expand_dims(image, axis=0)
predictions = MODEL.predict(image_batch)
predicted_class = class_names[np.argmax(predictions[0])]
confidence = np.max(predictions[0])
print("prediction", class_names[np.argmax(predictions)])
st.write("Predicted Class : ", predicted_class, " Confidence Level : ", confidence)
async def tomato():
if uploaded_file is not None:
image = Image.open(uploaded_file)
#
st.image(image, caption="Uploaded Image", width=250)
image = read_file_as_image(image)
image_batch = np.expand_dims(image, axis=0)
predictions = TOMATO_MODEL.predict(image_batch)
predicted_class = Tomato_classes[np.argmax(predictions[0])]
confidence = np.max(predictions[0])
print("prediction", Tomato_classes[np.argmax(predictions)])
st.write("Predicted Class : ", predicted_class, " Confidence Level : ", confidence)
async def pepper():
if uploaded_file is not None:
image = Image.open(uploaded_file)
#
st.image(image, caption="Uploaded Image", width=250)
image = read_file_as_image(image)
image_batch = np.expand_dims(image, axis=0)
predictions = PEEPER_MODEL.predict(image_batch)
predicted_class = pepper_classes[np.argmax(predictions[0])]
confidence = np.max(predictions[0])
print("prediction", pepper_classes[np.argmax(predictions)])
st.write("Predicted Class : ", predicted_class, " Confidence Level : ", confidence)
import asyncio
if __name__ == "__main__":
# if st.button('Predict'):
if selected_option == 'Potato':
asyncio.run(potato())
elif selected_option == 'Tomato':
asyncio.run(tomato())
elif selected_option == 'pepper':
asyncio.run(pepper())
else:
st.write("not avalible")