Spaces:
Sleeping
Sleeping
File size: 2,432 Bytes
787ddee edfadd2 787ddee d437262 787ddee |
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 67 68 69 70 |
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.
""")
|