Spaces:
Sleeping
Sleeping
Files uploaded
Browse files- app.py +66 -0
- cnn_model.h5 +3 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from tensorflow.keras.models import load_model
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import seaborn as sns
|
| 7 |
+
|
| 8 |
+
model = load_model('cnn_model.h5')
|
| 9 |
+
|
| 10 |
+
def process_image(img):
|
| 11 |
+
img = img.convert('RGB')
|
| 12 |
+
img = img.resize((64, 64))
|
| 13 |
+
img = np.array(img)
|
| 14 |
+
img = img / 255.0
|
| 15 |
+
img = np.expand_dims(img, axis=0)
|
| 16 |
+
return img
|
| 17 |
+
|
| 18 |
+
st.title('Grape Disease Detection :grapes:')
|
| 19 |
+
st.write('Upload a grape leaf image and the model will predict the disease category.')
|
| 20 |
+
|
| 21 |
+
file = st.file_uploader('Select an image', type=['jpg', 'jpeg', 'png'])
|
| 22 |
+
|
| 23 |
+
if file is not None:
|
| 24 |
+
img = Image.open(file)
|
| 25 |
+
st.image(img, caption='Uploaded Image', use_column_width=True)
|
| 26 |
+
|
| 27 |
+
image = process_image(img)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
with st.spinner('Classifying the image...'):
|
| 31 |
+
predictions = model.predict(image)
|
| 32 |
+
predicted_class = np.argmax(predictions)
|
| 33 |
+
predicted_prob = predictions[0][predicted_class]
|
| 34 |
+
|
| 35 |
+
class_names = ['ESCA', 'Healthy', 'Leaf Blight', 'Black Rot']
|
| 36 |
+
|
| 37 |
+
st.subheader(f"Prediction: {class_names[predicted_class]}")
|
| 38 |
+
st.write(f"Confidence: {predicted_prob * 100:.2f}%")
|
| 39 |
+
|
| 40 |
+
st.write("Prediction Probabilities for Each Class:")
|
| 41 |
+
probabilities = predictions[0]
|
| 42 |
+
|
| 43 |
+
prob_dict = {class_names[i]: probabilities[i] for i in range(len(class_names))}
|
| 44 |
+
|
| 45 |
+
sns.set(style="whitegrid")
|
| 46 |
+
|
| 47 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 48 |
+
|
| 49 |
+
ax.bar(list(prob_dict.keys()), list(prob_dict.values()), color='skyblue', edgecolor='black')
|
| 50 |
+
ax.set_ylabel('Probability', fontsize=14)
|
| 51 |
+
ax.set_title('Prediction Probabilities for Each Class', fontsize=16)
|
| 52 |
+
|
| 53 |
+
for index, value in enumerate(prob_dict.values()):
|
| 54 |
+
ax.text(index, value, f'{value * 100:.2f}%', va='bottom', ha='center', color='black', fontsize=12)
|
| 55 |
+
|
| 56 |
+
st.pyplot(fig)
|
| 57 |
+
|
| 58 |
+
st.write("This is the model's classification of the uploaded image based on the given grape leaf disease categories.")
|
| 59 |
+
|
| 60 |
+
st.markdown("""
|
| 61 |
+
### Grape Disease Categories:
|
| 62 |
+
- **ESCA**: A fungal disease affecting grapevines, causing leaf and wood symptoms.
|
| 63 |
+
- **Healthy**: No visible symptoms of disease.
|
| 64 |
+
- **Leaf Blight**: A condition causing necrotic lesions on the leaves of grapevines.
|
| 65 |
+
- **Black Rot**: A disease causing blackening and shriveling of grape berries.
|
| 66 |
+
""")
|
cnn_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1cbe54464e5a8abb7cb70f8f5fc0bf51ab526a22dbe52c9dfb7db0434885540e
|
| 3 |
+
size 55285296
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|