|
|
import streamlit as st
|
|
|
import tensorflow as tf
|
|
|
from PIL import Image
|
|
|
import numpy as np
|
|
|
import os
|
|
|
import pandas as pd
|
|
|
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def import_and_predict(image_data, model, class_labels):
|
|
|
size = (256, 256)
|
|
|
|
|
|
if image_data is not None:
|
|
|
image = Image.open(io.BytesIO(image_data.read()))
|
|
|
image = image.resize(size)
|
|
|
image = np.array(image)
|
|
|
img_reshape = image / 255.0
|
|
|
img_reshape = np.expand_dims(img_reshape, axis=0)
|
|
|
|
|
|
prediction = model.predict(img_reshape)
|
|
|
st.image(image, width=300)
|
|
|
predictions_label = class_labels[np.argmax(prediction[0])]
|
|
|
return predictions_label
|
|
|
else:
|
|
|
st.warning("Please upload an image.")
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.title("Plant Disease Detection")
|
|
|
|
|
|
selected_item = st.radio("Select an item:", ["Apple", "Mango", "Grape", "Tomato"])
|
|
|
|
|
|
if selected_item:
|
|
|
st.write(f"You selected: {selected_item}")
|
|
|
|
|
|
uploaded_image = st.file_uploader(f"Upload an image of {selected_item.lower()}", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
df = pd.read_excel('./final format.xlsx')
|
|
|
|
|
|
models_path = [
|
|
|
'./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']
|
|
|
|
|
|
@st.cache_resource
|
|
|
def load_model(models_path):
|
|
|
model = tf.keras.models.load_model(models_path)
|
|
|
return model
|
|
|
|
|
|
if selected_item == 'Apple':
|
|
|
CLASS_LABELS = ['apple scab', 'Apple black rot', 'cedar apple rust', 'Apple healthy']
|
|
|
|
|
|
model =load_model(models_path[0])
|
|
|
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
|
|
st.write("disease name: ", prediction)
|
|
|
|
|
|
|
|
|
if prediction != None:
|
|
|
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
|
|
st.markdown(new_title, unsafe_allow_html=True)
|
|
|
if prediction == CLASS_LABELS[0]:
|
|
|
response = df['Measures'].dropna().head(28)
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[1]:
|
|
|
response = df['Measures'].dropna()[28:46]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[2]:
|
|
|
response = df['Measures'].dropna()[46:63]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[3]:
|
|
|
st.write("Plant is healthy take good care of it")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif selected_item == 'Tomato':
|
|
|
|
|
|
CLASS_LABELS = ['Tomato Early blight', 'Tomato Leaf Mold', 'Tomato YellowLeaf Curl Virus',
|
|
|
'Tomato mosaic virus', 'Tomato healthy']
|
|
|
|
|
|
model =load_model(models_path[1])
|
|
|
|
|
|
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
|
|
st.write("disease name: ", prediction)
|
|
|
|
|
|
|
|
|
if prediction != None:
|
|
|
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
|
|
st.markdown(new_title, unsafe_allow_html=True)
|
|
|
if prediction == CLASS_LABELS[0]:
|
|
|
response = df['Measures'].dropna()[63:79]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[1]:
|
|
|
response = df['Measures'].dropna()[187:196]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[2]:
|
|
|
response = df['Measures'].dropna()[99:113]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[3]:
|
|
|
response = df['Measures'].dropna()[79:99]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[4]:
|
|
|
st.write("Plant is healthy take good care of it")
|
|
|
|
|
|
elif selected_item == 'Grape':
|
|
|
|
|
|
CLASS_LABELS = ['Grape Black rot', 'Grape Black Measles','Grape Leaf blight', 'Grape healthy']
|
|
|
|
|
|
model =load_model(models_path[2])
|
|
|
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
|
|
st.write("disease name: ", prediction)
|
|
|
|
|
|
if prediction != None:
|
|
|
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
|
|
st.markdown(new_title, unsafe_allow_html=True)
|
|
|
if prediction == CLASS_LABELS[0]:
|
|
|
response = df['Measures'].dropna()[123:134]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[1]:
|
|
|
response = df['Measures'].dropna()[196:204]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[2]:
|
|
|
response = df['Measures'].dropna()[113:123]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
elif prediction == CLASS_LABELS[3]:
|
|
|
st.write("Plant is healthy take good care of it")
|
|
|
|
|
|
|
|
|
elif selected_item == 'Mango':
|
|
|
|
|
|
CLASS_LABELS = ['Anthracnose', 'Bacterial Canker', 'Cutting Weevil', 'Die Back', 'Gall Midge', 'Healthy','Sooty Mould' ,'Powdery Mildew']
|
|
|
|
|
|
model =load_model(models_path[3])
|
|
|
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
|
|
st.write("disease name: ", prediction)
|
|
|
|
|
|
if prediction != None:
|
|
|
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
|
|
st.markdown(new_title, unsafe_allow_html=True)
|
|
|
|
|
|
if prediction == CLASS_LABELS[0]:
|
|
|
response = df['Measures'].dropna()[134:151]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[1]:
|
|
|
response = df['Measures'].dropna()[151:165]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[2]:
|
|
|
response = df['Measures'].dropna()[164:173]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[3]:
|
|
|
response = df['Measures'].dropna()[172:180]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[4]:
|
|
|
response = df['Measures'].dropna()[181:189]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[5]:
|
|
|
st.write("Plant is healthy take good care of it")
|
|
|
|
|
|
elif prediction == CLASS_LABELS[6]:
|
|
|
response = df['Measures'].dropna()[164:174]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|
|
|
elif prediction == CLASS_LABELS[7]:
|
|
|
response = df['Measures'].dropna()[174:189]
|
|
|
response_text = " ".join([f"<p style='font-size: 18px;'>{text}</p>" for text in response])
|
|
|
st.write(response_text, unsafe_allow_html=True)
|
|
|
|