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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import io
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def import_and_predict(image_data, model, class_labels):
|
| 13 |
+
size = (256, 256)
|
| 14 |
+
|
| 15 |
+
if image_data is not None:
|
| 16 |
+
image = Image.open(io.BytesIO(image_data.read()))
|
| 17 |
+
image = image.resize(size)
|
| 18 |
+
image = np.array(image)
|
| 19 |
+
img_reshape = image / 255.0
|
| 20 |
+
img_reshape = np.expand_dims(img_reshape, axis=0)
|
| 21 |
+
|
| 22 |
+
prediction = model.predict(img_reshape)
|
| 23 |
+
st.image(image, width=300)
|
| 24 |
+
predictions_label = class_labels[np.argmax(prediction[0])]
|
| 25 |
+
return predictions_label
|
| 26 |
+
else:
|
| 27 |
+
st.warning("Please upload an image.")
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
st.title("Plant Disease Detection")
|
| 34 |
+
|
| 35 |
+
selected_item = st.radio("Select an item:", ["Apple", "Mango", "Grape", "Tomato"])
|
| 36 |
+
|
| 37 |
+
if selected_item:
|
| 38 |
+
st.write(f"You selected: {selected_item}")
|
| 39 |
+
|
| 40 |
+
uploaded_image = st.file_uploader(f"Upload an image of {selected_item.lower()}", type=["jpg", "jpeg", "png"])
|
| 41 |
+
|
| 42 |
+
df = pd.read_excel('./final format.xlsx')
|
| 43 |
+
|
| 44 |
+
models_path = [
|
| 45 |
+
'./models/best_model_50_apple_plant (1).h5','./models/best_model_100_subset (1).h5','./models/best_model_50_grape_plant2.h5','./models/model_inception_epoch_50_mango.h5']
|
| 46 |
+
|
| 47 |
+
@st.cache_resource
|
| 48 |
+
def load_model(models_path):
|
| 49 |
+
model = tf.keras.models.load_model(models_path)
|
| 50 |
+
return model
|
| 51 |
+
|
| 52 |
+
if selected_item == 'Apple':
|
| 53 |
+
CLASS_LABELS = ['apple scab', 'Apple black rot', 'cedar apple rust', 'Apple healthy']
|
| 54 |
+
|
| 55 |
+
model =load_model(models_path[0])
|
| 56 |
+
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
| 57 |
+
st.write("disease name: ", prediction)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if prediction != None:
|
| 61 |
+
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
| 62 |
+
st.markdown(new_title, unsafe_allow_html=True)
|
| 63 |
+
if prediction == CLASS_LABELS[0]:
|
| 64 |
+
response = df['Measures'].dropna().head(28)
|
| 65 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 66 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 67 |
+
|
| 68 |
+
elif prediction == CLASS_LABELS[1]:
|
| 69 |
+
response = df['Measures'].dropna()[28:46]
|
| 70 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 71 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 72 |
+
|
| 73 |
+
elif prediction == CLASS_LABELS[2]:
|
| 74 |
+
response = df['Measures'].dropna()[46:63]
|
| 75 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 76 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 77 |
+
|
| 78 |
+
elif prediction == CLASS_LABELS[3]:
|
| 79 |
+
st.write("Plant is healthy take good care of it")
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
elif selected_item == 'Tomato':
|
| 86 |
+
|
| 87 |
+
CLASS_LABELS = ['Tomato Early blight', 'Tomato Leaf Mold', 'Tomato YellowLeaf Curl Virus',
|
| 88 |
+
'Tomato mosaic virus', 'Tomato healthy']
|
| 89 |
+
|
| 90 |
+
model =load_model(models_path[1])
|
| 91 |
+
|
| 92 |
+
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
| 93 |
+
st.write("disease name: ", prediction)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if prediction != None:
|
| 97 |
+
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
| 98 |
+
st.markdown(new_title, unsafe_allow_html=True)
|
| 99 |
+
if prediction == CLASS_LABELS[0]:
|
| 100 |
+
response = df['Measures'].dropna()[63:79]
|
| 101 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 102 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 103 |
+
|
| 104 |
+
elif prediction == CLASS_LABELS[1]: # remaining
|
| 105 |
+
response = df['Measures'].dropna()[187:196]
|
| 106 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 107 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 108 |
+
|
| 109 |
+
elif prediction == CLASS_LABELS[2]:
|
| 110 |
+
response = df['Measures'].dropna()[99:113]
|
| 111 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 112 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 113 |
+
|
| 114 |
+
elif prediction == CLASS_LABELS[3]:
|
| 115 |
+
response = df['Measures'].dropna()[79:99]
|
| 116 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 117 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 118 |
+
|
| 119 |
+
elif prediction == CLASS_LABELS[4]:
|
| 120 |
+
st.write("Plant is healthy take good care of it")
|
| 121 |
+
|
| 122 |
+
elif selected_item == 'Grape':
|
| 123 |
+
|
| 124 |
+
CLASS_LABELS = ['Grape Black rot', 'Grape Black Measles','Grape Leaf blight', 'Grape healthy']
|
| 125 |
+
|
| 126 |
+
model =load_model(models_path[2])
|
| 127 |
+
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
| 128 |
+
st.write("disease name: ", prediction)
|
| 129 |
+
|
| 130 |
+
if prediction != None:
|
| 131 |
+
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
| 132 |
+
st.markdown(new_title, unsafe_allow_html=True)
|
| 133 |
+
if prediction == CLASS_LABELS[0]:
|
| 134 |
+
response = df['Measures'].dropna()[123:134]
|
| 135 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 136 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 137 |
+
|
| 138 |
+
elif prediction == CLASS_LABELS[1]:
|
| 139 |
+
response = df['Measures'].dropna()[196:204] #Remaining
|
| 140 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 141 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 142 |
+
|
| 143 |
+
elif prediction == CLASS_LABELS[2]:
|
| 144 |
+
response = df['Measures'].dropna()[113:123]
|
| 145 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 146 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
elif prediction == CLASS_LABELS[3]:
|
| 150 |
+
st.write("Plant is healthy take good care of it")
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
elif selected_item == 'Mango':
|
| 154 |
+
|
| 155 |
+
CLASS_LABELS = ['Anthracnose', 'Bacterial Canker', 'Cutting Weevil', 'Die Back', 'Gall Midge', 'Healthy','Sooty Mould' ,'Powdery Mildew']
|
| 156 |
+
|
| 157 |
+
model =load_model(models_path[3])
|
| 158 |
+
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
| 159 |
+
st.write("disease name: ", prediction)
|
| 160 |
+
|
| 161 |
+
if prediction != None:
|
| 162 |
+
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
| 163 |
+
st.markdown(new_title, unsafe_allow_html=True)
|
| 164 |
+
|
| 165 |
+
if prediction == CLASS_LABELS[0]:
|
| 166 |
+
response = df['Measures'].dropna()[134:151]
|
| 167 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 168 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 169 |
+
|
| 170 |
+
elif prediction == CLASS_LABELS[1]:
|
| 171 |
+
response = df['Measures'].dropna()[151:165]
|
| 172 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 173 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 174 |
+
|
| 175 |
+
elif prediction == CLASS_LABELS[2]:
|
| 176 |
+
response = df['Measures'].dropna()[164:173]
|
| 177 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response]) #remaining 2,3,4
|
| 178 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 179 |
+
|
| 180 |
+
elif prediction == CLASS_LABELS[3]:
|
| 181 |
+
response = df['Measures'].dropna()[172:180]
|
| 182 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 183 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 184 |
+
|
| 185 |
+
elif prediction == CLASS_LABELS[4]:
|
| 186 |
+
response = df['Measures'].dropna()[181:189]
|
| 187 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 188 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 189 |
+
|
| 190 |
+
elif prediction == CLASS_LABELS[5]:
|
| 191 |
+
st.write("Plant is healthy take good care of it")
|
| 192 |
+
|
| 193 |
+
elif prediction == CLASS_LABELS[6]:
|
| 194 |
+
response = df['Measures'].dropna()[164:174]
|
| 195 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 196 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 197 |
+
|
| 198 |
+
elif prediction == CLASS_LABELS[7]:
|
| 199 |
+
response = df['Measures'].dropna()[174:189]
|
| 200 |
+
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
| 201 |
+
st.write(response_text, unsafe_allow_html=True)
|
| 202 |
+
|
final format.xlsx
ADDED
|
Binary file (19.9 kB). View file
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|
| 4 |
+
google.generativeai
|
| 5 |
+
Ipython
|
| 6 |
+
openpyxl
|