-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (53 loc) · 2.7 KB
/
Copy pathapp.py
File metadata and controls
66 lines (53 loc) · 2.7 KB
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
import streamlit as st
import tensorflow as tf
import numpy as np
import gdown
import os
file_id = "1Pg7CWZWxqA5KQovUXLjBPKkQ5ACp0dna"
url = 'https://drive.google.com/file/d/1Pg7CWZWxqA5KQovUXLjBPKkQ5ACp0dna/view?usp=sharing'
model_path = "trained_plant_disease1_model.keras"
if not os.path.exists(model_path):
st.warning("Downloading model from Google Drive...")
gdown.download(url, model_path, quiet=False)
model_path = "trained_plant_disease1_model.keras"
def model_prediction(test_image):
model = tf.keras.models.load_model(model_path)
image = tf.keras.preprocessing.image.load_img(test_image,target_size=(128,128))
input_arr = tf.keras.preprocessing.image.img_to_array(image)
input_arr = np.array([input_arr]) #convert single image to batch
predictions = model.predict(input_arr)
return np.argmax(predictions) #return index of max element
#Sidebar
st.sidebar.title("PotatoVision: CNN-Driven Detection of Leaf Diseases for Sustainable Agriculture")
app_mode = st.sidebar.selectbox("Select Page",["HOME","DISEASE RECOGNITION"])
#app_mode = st.sidebar.selectbox("Select Page",["Home"," ","Disease Recognition"])
# import Image from pillow to open images
from PIL import Image
img = Image.open("Diseases1.jpg")
# display image using streamlit
# width is used to set the width of an image
st.image(img)
st.sidebar.write("### About the Developer")
st.sidebar.write("**Bipin Gundala**")
st.sidebar.write("I am a software developer with a passion for building machine learning applications.")
st.sidebar.write("This project is aimed at helping farmers identify plant diseases using deep learning.")
st.sidebar.write("**Contact Information:**")
st.sidebar.write("- **Email:** bipin.gundala@gmail.com")
st.sidebar.write("- **LinkedIn:** [LinkedIn Profile](https://www.linkedin.com/in/bipin-gundala-b54496210/)")
#Main Page
if(app_mode=="HOME"):
st.markdown("<h1 style='text-align: center;'>PotatoVision: CNN-Driven Detection of Leaf Diseases for Sustainable Agriculture", unsafe_allow_html=True)
#Prediction Page
elif(app_mode=="DISEASE RECOGNITION"):
st.header("PotatoVision: CNN-Driven Detection of Leaf Diseases for Sustainable Agriculture")
test_image = st.file_uploader("Choose an Image:")
if(st.button("Show Image")):
st.image(test_image,width=4,use_column_width=True)
#Predict button
if(st.button("Predict")):
st.snow()
st.write("Our Prediction")
result_index = model_prediction(test_image)
#Reading Labels
class_name = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
st.success("Model is Predicting it's a {}".format(class_name[result_index]))