Upload 3 files
Browse files- app.py +49 -0
- plant_model.h5 +3 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from tensorflow import keras
|
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 |
+
# prediction function
|
17 |
+
|
18 |
+
def prediction(file):
|
19 |
+
img = tf.keras.utils.load_img(file, target_size=(512, 512))
|
20 |
+
x = tf.keras.utils.img_to_array(img)
|
21 |
+
x = np.expand_dims(x, axis=0)
|
22 |
+
|
23 |
+
# predict the class probabilities
|
24 |
+
|
25 |
+
classes = model.predict(x)
|
26 |
+
|
27 |
+
# get the predicted class label
|
28 |
+
|
29 |
+
classes = np.ravel(classes) # convert to 1D array
|
30 |
+
idx = np.argmax(classes)
|
31 |
+
class_name = ['Healthy', 'Powdery', 'Rust'][idx]
|
32 |
+
|
33 |
+
return class_name
|
34 |
+
|
35 |
+
# file uploader
|
36 |
+
|
37 |
+
uploaded_file = st.file_uploader("Choose a leaf picture:")
|
38 |
+
if uploaded_file is not None:
|
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 |
+
result = prediction(uploaded_file)
|
49 |
+
st.write('Prediction is {}'.format(result))
|
plant_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:455355eb14a60440c66483c4f8571daffebca33cda65a562cfe29aac93812a4d
|
3 |
+
size 243915080
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
scikit-learn
|
4 |
+
tensorflow
|
5 |
+
keras
|
6 |
+
matplotlib
|