prasanth345 commited on
Commit
d072441
·
verified ·
1 Parent(s): c96091e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ def model_prediction(test_image):
5
+ model = tf.keras.models.load_model("trained_plant_disease_model.keras")
6
+ image = tf.keras.preprocessing.image.load_img(test_image,target_size=(128,128))
7
+ input_arr = tf.keras.preprocessing.image.img_to_array(image)
8
+ input_arr = np.array([input_arr]) #convert single image to batch
9
+ predictions = model.predict(input_arr)
10
+ return np.argmax(predictions) #return index of max element
11
+
12
+ #Sidebar
13
+ st.sidebar.title("AgriSens")
14
+ app_mode = st.sidebar.selectbox("Select Page",["HOME","DISEASE RECOGNITION"])
15
+ #app_mode = st.sidebar.selectbox("Select Page",["Home","About","Disease Recognition"])
16
+
17
+ # import Image from pillow to open images
18
+ from PIL import Image
19
+
20
+
21
+
22
+ img = Image.open("Diseases.png")
23
+
24
+ # display image using streamlit
25
+ # width is used to set the width of an image
26
+ st.image(img)
27
+
28
+ #Main Page
29
+ if(app_mode=="HOME"):
30
+ st.markdown("<h1 style='text-align: center;'>SMART DISEASE DETECTION", unsafe_allow_html=True)
31
+
32
+ #Prediction Page
33
+ elif(app_mode=="DISEASE RECOGNITION"):
34
+ st.header("DISEASE RECOGNITION")
35
+ test_image = st.file_uploader("Choose an Image:")
36
+ if(st.button("Show Image")):
37
+ st.image(test_image,width=4,use_column_width=True)
38
+ #Predict button
39
+ if(st.button("Predict")):
40
+ st.snow()
41
+ st.write("Our Prediction")
42
+ result_index = model_prediction(test_image)
43
+ #Reading Labels
44
+ class_name = ['Apple___Apple_scab', 'Apple___Black_rot', 'Apple___Cedar_apple_rust', 'Apple___healthy',
45
+ 'Blueberry___healthy', 'Cherry_(including_sour)___Powdery_mildew',
46
+ 'Cherry_(including_sour)___healthy', 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot',
47
+ 'Corn_(maize)___Common_rust_', 'Corn_(maize)___Northern_Leaf_Blight', 'Corn_(maize)___healthy',
48
+ 'Grape___Black_rot', 'Grape___Esca_(Black_Measles)', 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)',
49
+ 'Grape___healthy', 'Orange___Haunglongbing_(Citrus_greening)', 'Peach___Bacterial_spot',
50
+ 'Peach___healthy', 'Pepper,_bell___Bacterial_spot', 'Pepper,_bell___healthy',
51
+ 'Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy',
52
+ 'Raspberry___healthy', 'Soybean___healthy', 'Squash___Powdery_mildew',
53
+ 'Strawberry___Leaf_scorch', 'Strawberry___healthy', 'Tomato___Bacterial_spot',
54
+ 'Tomato___Early_blight', 'Tomato___Late_blight', 'Tomato___Leaf_Mold',
55
+ 'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-spotted_spider_mite',
56
+ 'Tomato___Target_Spot', 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus',
57
+ 'Tomato___healthy']
58
+ st.success("Model is Predicting it's a {}".format(class_name[result_index]))