import streamlit as st from tensorflow.keras.models import load_model from PIL import Image import numpy as np import matplotlib.pyplot as plt import seaborn as sns import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) model = load_model('cnn_model.h5') def process_image(img): img = img.convert('RGB') img = img.resize((64, 64)) img = np.array(img) img = img / 255.0 img = np.expand_dims(img, axis=0) return img st.title('Grape Disease Detection :grapes:') st.write('Upload a grape leaf image and the model will predict the disease category.') file = st.file_uploader('Select an image', type=['jpg', 'jpeg', 'png']) if file is not None: img = Image.open(file) st.image(img, caption='Uploaded Image', use_container_width=True) image = process_image(img) with st.spinner('Classifying the image...'): predictions = model.predict(image) predicted_class = np.argmax(predictions) predicted_prob = predictions[0][predicted_class] class_names = ['ESCA', 'Healthy', 'Leaf Blight', 'Black Rot'] st.subheader(f"Prediction: {class_names[predicted_class]}") st.write(f"Confidence: {predicted_prob * 100:.2f}%") st.write("Prediction Probabilities for Each Class:") probabilities = predictions[0] prob_dict = {class_names[i]: probabilities[i] for i in range(len(class_names))} sns.set(style="whitegrid") fig, ax = plt.subplots(figsize=(10, 6)) ax.bar(list(prob_dict.keys()), list(prob_dict.values()), color='skyblue', edgecolor='black') ax.set_ylabel('Probability', fontsize=14) ax.set_title('Prediction Probabilities for Each Class', fontsize=16) for index, value in enumerate(prob_dict.values()): ax.text(index, value, f'{value * 100:.2f}%', va='bottom', ha='center', color='black', fontsize=12) st.pyplot(fig) st.write("This is the model's classification of the uploaded image based on the given grape leaf disease categories.") st.markdown(""" ### Grape Disease Categories: - **ESCA**: A fungal disease affecting grapevines, causing leaf and wood symptoms. - **Healthy**: No visible symptoms of disease. - **Leaf Blight**: A condition causing necrotic lesions on the leaves of grapevines. - **Black Rot**: A disease causing blackening and shriveling of grape berries. """)