Senasu commited on
Commit
d0501e5
·
verified ·
1 Parent(s): c9034f6

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +96 -0
  2. cnn_model.h5 +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Load the trained model
9
+ model = load_model('cnn_model.h5')
10
+
11
+ # Function to process the uploaded image
12
+ def process_image(img):
13
+ img = img.convert('RGB')
14
+ img = img.resize((32, 32))
15
+ img = np.array(img)
16
+ img = img / 255.0
17
+ img = np.expand_dims(img, axis=0)
18
+ return img
19
+
20
+ # Frontend design
21
+ st.set_page_config(page_title="Cassava Leaf Disease Image Classification", layout="wide")
22
+ st.title("Cassava Leaf Disease Image Classification")
23
+ st.markdown("""
24
+ This web application helps in classifying cassava leaf diseases based on an uploaded image.
25
+ Simply upload a cassava leaf image, and the model will predict the disease and display the probabilities for each class.
26
+ """)
27
+
28
+ # Image upload
29
+ file = st.file_uploader('Select an image (JPG, JPEG, PNG)', type=['jpg', 'jpeg', 'png'])
30
+
31
+ if file is not None:
32
+ # Display uploaded image
33
+ img = Image.open(file)
34
+ st.image(img, caption='Uploaded Image', use_column_width=True)
35
+
36
+ # Preprocess the image
37
+ image = process_image(img)
38
+
39
+ # Model prediction
40
+ with st.spinner('Classifying the image...'):
41
+ predictions = model.predict(image)
42
+ predicted_class = np.argmax(predictions)
43
+ predicted_prob = predictions[0][predicted_class]
44
+
45
+ # Class names for prediction
46
+ class_names = ["Cassava Bacterial Blight (CBB)", "Cassava Brown Streak Disease (CBSD)",
47
+ "Cassava Green Mottle (CGM)", "Cassava Mosaic Disease (CMD)", "Healthy"]
48
+
49
+ # Display the prediction result
50
+ st.subheader(f"**Prediction:** {class_names[predicted_class]}")
51
+ st.write(f"**Confidence:** {predicted_prob * 100:.2f}%")
52
+
53
+ # Display prediction probabilities
54
+ st.write("**Prediction Probabilities for Each Class:**")
55
+
56
+ # Prepare probabilities for visualization
57
+ probabilities = predictions[0]
58
+ prob_dict = {class_names[i]: probabilities[i] for i in range(len(class_names))}
59
+
60
+ # Plot settings
61
+ sns.set(style="whitegrid", palette="muted") # Use a muted color palette for the plot
62
+
63
+ # Create the figure for the bar chart
64
+ fig, ax = plt.subplots(figsize=(12, 6)) # Adjust figure size for better readability
65
+
66
+ # Plot the bar chart with a color palette
67
+ ax.bar(list(prob_dict.keys()), list(prob_dict.values()), color=sns.color_palette("Blues", len(class_names)), edgecolor='black')
68
+ ax.set_ylabel('Probability', fontsize=14, color='black')
69
+ ax.set_title('Prediction Probabilities for Each Class', fontsize=18, color='black')
70
+
71
+ # Rotate x-axis labels for better readability
72
+ plt.xticks(rotation=45, ha='right', fontsize=12)
73
+
74
+ # Annotate bars with percentage values
75
+ for index, value in enumerate(prob_dict.values()):
76
+ ax.text(index, value, f'{value * 100:.0f}%', va='bottom', ha='center', fontsize=10, color='black')
77
+
78
+ # Style improvements: Remove background grid and spines
79
+ ax.spines['top'].set_visible(False)
80
+ ax.spines['right'].set_visible(False)
81
+ ax.spines['left'].set_visible(False)
82
+ ax.spines['bottom'].set_visible(False)
83
+ ax.grid(False)
84
+
85
+ # Adjust layout to prevent clipping
86
+ fig.tight_layout()
87
+
88
+ # Display the plot in Streamlit
89
+ st.pyplot(fig)
90
+
91
+ # Footer section
92
+ st.markdown("""
93
+ ---
94
+ **Cassava Leaf Disease Image Classification** | Developed with ❤️ by Senasu Demir
95
+ For more information, visit [Your Website or Contact Info].
96
+ """)
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d4c3a7096e7d1ef8546a3be37880878faae5529d1d15c3b8549831b45747666
3
+ size 96313928
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ Pillow
4
+ matplotlib
5
+ seaborn