Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,44 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
from tensorflow import
|
5 |
-
import tensorflow as tf
|
6 |
-
from keras.models import load_model
|
7 |
-
import matplotlib.pyplot as plt
|
8 |
from PIL import Image
|
9 |
|
10 |
st.title('Plant Disease Recognition')
|
11 |
|
12 |
-
# import model
|
13 |
|
14 |
model = load_model('plant_model.h5')
|
15 |
|
16 |
-
#
|
17 |
|
18 |
-
def
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
classes = model.predict(x)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
classes =
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
return
|
34 |
|
35 |
# file uploader
|
36 |
|
37 |
uploaded_file = st.file_uploader("Upload your leaf picture.")
|
38 |
-
|
39 |
-
image = Image.open(uploaded_file)
|
40 |
-
image = image.resize((240, 240))
|
41 |
-
image = tf.keras.preprocessing.image.img_to_array(image)
|
42 |
-
image = image / 255.0
|
43 |
-
image = tf.expand_dims(image, axis=0)
|
44 |
-
|
45 |
# result
|
46 |
|
47 |
if st.button('Predict'):
|
48 |
if uploaded_file is None:
|
49 |
st.write('Please upload a leaf picture first.')
|
50 |
else:
|
51 |
-
|
52 |
-
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
|
|
|
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
st.title('Plant Disease Recognition')
|
7 |
|
8 |
+
# import the model
|
9 |
|
10 |
model = load_model('plant_model.h5')
|
11 |
|
12 |
+
# define the preprocessing function
|
13 |
|
14 |
+
def preprocess_image(image):
|
15 |
+
image = image.resize((240, 240)) # resize the image to the desired dimensions
|
16 |
+
image = image.convert("RGB") # convert the image to RGB mode if needed
|
17 |
+
image = np.array(image) # convert the image to a NumPy array
|
18 |
+
image = image / 255.0 # normalize the pixel values to the range of 0 to 1
|
19 |
+
image = np.expand_dims(image, axis=0) # add an extra dimension for batch size
|
20 |
+
return image
|
21 |
|
22 |
+
# define the prediction function
|
|
|
|
|
23 |
|
24 |
+
def prediction(image):
|
25 |
+
preprocessed_image = preprocess_image(image)
|
26 |
+
classes = model.predict(preprocessed_image)
|
27 |
+
predicted_class_index = np.argmax(classes)
|
28 |
+
class_labels = ['Healthy', 'Powdery', 'Rust']
|
29 |
+
predicted_class = class_labels[predicted_class_index]
|
30 |
+
return predicted_class
|
31 |
|
32 |
# file uploader
|
33 |
|
34 |
uploaded_file = st.file_uploader("Upload your leaf picture.")
|
35 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# result
|
37 |
|
38 |
if st.button('Predict'):
|
39 |
if uploaded_file is None:
|
40 |
st.write('Please upload a leaf picture first.')
|
41 |
else:
|
42 |
+
image = Image.open(uploaded_file)
|
43 |
+
result = prediction(image)
|
44 |
+
st.write('This leaf belongs to the {} class.'.format(result))
|