Aniket1409 commited on
Commit
61faec6
·
verified ·
1 Parent(s): 875365f

Upload 5 files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. app.py +76 -0
  3. model.keras +3 -0
  4. plant_disease_data.csv +39 -0
  5. plant_disease_data.py +210 -0
  6. requirements.txt +7 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Libraries
2
+ import streamlit as st
3
+ import tensorflow as tf
4
+ import numpy as np
5
+ import pandas as pd
6
+ from PIL import Image, UnidentifiedImageError
7
+
8
+ # Load Function (requires combined_disease_data.csv)
9
+ def load_disease_data():
10
+ df = pd.read_csv("plant_disease_data.csv")
11
+ disease_db = {} # empty dictionary
12
+ for i, row in df.iterrows():
13
+ if row['Disease'] != 'N/A':
14
+ disease_db[row['Disease']] = {
15
+ "symptoms": row['Symptoms'],
16
+ "treatment": row['Treatment']
17
+ }
18
+ return disease_db, df['Class Name'].unique().tolist()
19
+ disease_db, class_name = load_disease_data()
20
+
21
+ # Model Function
22
+ def model_prediction(test_image):
23
+ model = tf.keras.models.load_model('model.keras')
24
+ image = tf.keras.preprocessing.image.load_img(test_image, target_size=(128, 128))
25
+ input_arr = tf.keras.preprocessing.image.img_to_array(image)
26
+ input_arr = np.array([input_arr]) # Convert to batch
27
+ prediction = model.predict(input_arr) # Predict on array
28
+ return np.argmax(prediction), prediction # Both index and prediction array
29
+
30
+ st.title("Plant Disease Scanner")
31
+
32
+ # Camera Input, Drag & Drop Uploader
33
+ img_file_buffer = st.camera_input("Take a photo of the leaf")
34
+ if img_file_buffer:
35
+ test_image = img_file_buffer
36
+ else:
37
+ test_image = st.file_uploader("Upload a plant leaf photo: ", type=['jpg','jpeg','png'],
38
+ key="uploader", accept_multiple_files=False,
39
+ help="Take or upload a clear photo of a plant leaf")
40
+
41
+ # Image Error Handling
42
+ if test_image is not None:
43
+ try: Image.open(test_image); st.image(test_image, use_column_width=True)
44
+ except UnidentifiedImageError:
45
+ st.error("⚠️ Invalid image"); test_image = None # Clear the invalid upload
46
+ except Exception as e:
47
+ st.error(f"⚠️ Error reading image: {str(e)}"); test_image = None
48
+
49
+ # Predict Button with loading spinner, confidence meter, result (green), error (red)
50
+ if st.button("Predict Disease"):
51
+ if test_image is None:
52
+ st.warning("⚠️ Please upload an image first!")
53
+ else:
54
+ with st.spinner("Analyzing the image..."):
55
+ try:
56
+ result_index, predictions = model_prediction(test_image)
57
+ confidence = np.max(predictions) * 100
58
+ st.success(f"🌱 {class_name[result_index]}")
59
+ st.progress(int(confidence))
60
+ st.caption(f"Confidence: {confidence:.1f}%")
61
+ if result_index is not None:
62
+ with st.expander(f"ℹ️ About {class_name[result_index]}"):
63
+ disease_info = disease_db.get(class_name[result_index],
64
+ {"symptoms": "Information not available",
65
+ "treatment": "Consult an agricultural expert"})
66
+ st.subheader("Symptoms")
67
+ st.write(disease_info["symptoms"])
68
+ st.subheader("Treatment")
69
+ st.write(disease_info["treatment"])
70
+
71
+ except TypeError:
72
+ st.error("⚠️ Invalid file format - please upload an image")
73
+ except UnidentifiedImageError:
74
+ st.error("⚠️ Corrupt image - please try another file")
75
+ except Exception as e:
76
+ st.error(f"⚠️ Prediction failed: {str(e)}")
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47aeb1894b0b47a4dc2f0d6553979737ffa86b648eeb758a131763dd077a93ee
3
+ size 94230432
plant_disease_data.csv ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Class Name,Disease,Symptoms,Treatment
2
+ Apple___Apple_scab,Apple___Apple_scab,"Olive-green to black spots on leaves, may cause leaf drop","Apply fungicides like myclobutanil, prune affected branches"
3
+ Apple___Black_rot,Apple___Black_rot,"Brown spots with concentric rings, shriveled fruits","Remove infected plant material, apply captan fungicide"
4
+ Apple___Cedar_apple_rust,Apple___Cedar_apple_rust,"Yellow-orange spots on leaves, gelatinous growths","Remove nearby junipers, apply fungicides in early spring"
5
+ Apple___healthy,Apple___healthy,No visible disease symptoms,Maintain proper watering and fertilization
6
+ Blueberry___healthy,Blueberry___healthy,No visible disease symptoms,Ensure acidic soil conditions and proper pruning
7
+ Cherry_(including_sour)___Powdery_mildew,Cherry_(including_sour)___Powdery_mildew,White powdery spots on leaves and shoots,Apply sulfur or potassium bicarbonate fungicides
8
+ Cherry_(including_sour)___healthy,Cherry_(including_sour)___healthy,No visible disease symptoms,Maintain good air circulation around trees
9
+ Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot,Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot,Rectangular tan lesions with dark borders on leaves,"Rotate crops, use resistant varieties"
10
+ Corn_(maize)___Common_rust_,Corn_(maize)___Common_rust_,"Small, round to elongate golden brown pustules",Apply fungicides at first sign of disease
11
+ Corn_(maize)___Northern_Leaf_Blight,Corn_(maize)___Northern_Leaf_Blight,"Long, elliptical gray-green lesions","Use resistant hybrids, practice crop rotation"
12
+ Corn_(maize)___healthy,Corn_(maize)___healthy,No visible disease symptoms,Maintain proper plant spacing
13
+ Grape___Black_rot,Grape___Black_rot,Brown leaf spots with black fruiting bodies,"Apply fungicides before flowering, remove infected berries"
14
+ Grape___Esca_(Black_Measles),Grape___Esca_(Black_Measles),"Tiger-stripe patterns on leaves, wood decay","Prune affected wood, apply wound protectants"
15
+ Grape___Leaf_blight_(Isariopsis_Leaf_Spot),Grape___Leaf_blight_(Isariopsis_Leaf_Spot),Angular brown spots with yellow halos,Apply copper-based fungicides
16
+ Grape___healthy,Grape___healthy,No visible disease symptoms,Maintain proper trellising and pruning
17
+ Orange___Haunglongbing_(Citrus_greening),Orange___Haunglongbing_(Citrus_greening),"Yellow shoots, lopsided bitter fruit","Remove infected trees, control psyllid vectors"
18
+ Peach___Bacterial_spot,Peach___Bacterial_spot,"Dark, angular leaf spots, fruit cracking",Apply copper sprays during dormancy
19
+ Peach___healthy,Peach___healthy,No visible disease symptoms,Prune to improve air circulation
20
+ "Pepper,_bell___Bacterial_spot","Pepper,_bell___Bacterial_spot",Small water-soaked spots that turn brown,"Use disease-free seed, apply copper sprays"
21
+ "Pepper,_bell___healthy","Pepper,_bell___healthy",No visible disease symptoms,Avoid overhead watering
22
+ Potato___Early_blight,Potato___Early_blight,Small brown spots with target-like rings,"Rotate crops, apply chlorothalonil fungicides"
23
+ Potato___Late_blight,Potato___Late_blight,Greasy-looking dark lesions that spread quickly,"Destroy infected plants, use copper fungicides"
24
+ Potato___healthy,Potato___healthy,No visible disease symptoms,Hill soil around plants
25
+ Raspberry___healthy,Raspberry___healthy,No visible disease symptoms,Remove old canes after fruiting
26
+ Soybean___healthy,Soybean___healthy,No visible disease symptoms,Rotate with non-legume crops
27
+ Squash___Powdery_mildew,Squash___Powdery_mildew,White powdery coating on leaves,Apply sulfur or horticultural oil
28
+ Strawberry___Leaf_scorch,Strawberry___Leaf_scorch,Purple spots with white centers on leaves,"Remove infected leaves, improve air flow"
29
+ Strawberry___healthy,Strawberry___healthy,No visible disease symptoms,Renew beds every 2-3 years
30
+ Tomato___Bacterial_spot,Tomato___Bacterial_spot,Small water-soaked spots with yellow halos,"Use pathogen-free seed, apply copper sprays"
31
+ Tomato___Early_blight,Tomato___Early_blight,Dark spots with concentric rings on lower leaves,"Remove affected leaves, apply copper-based fungicides"
32
+ Tomato___Late_blight,Tomato___Late_blight,Water-soaked lesions that turn brown and spread rapidly,"Destroy infected plants, use chlorothalonil fungicides"
33
+ Tomato___Leaf_Mold,Tomato___Leaf_Mold,Yellow spots with olive-green undersides,"Reduce humidity, apply fungicides"
34
+ Tomato___Septoria_leaf_spot,Tomato___Septoria_leaf_spot,Small circular spots with dark borders,"Remove lower leaves, apply copper fungicides"
35
+ Tomato___Spider_mites Two-spotted_spider_mite,Tomato___Spider_mites Two-spotted_spider_mite,"Fine webbing, stippled yellow leaves","Apply miticides, increase humidity"
36
+ Tomato___Target_Spot,Tomato___Target_Spot,Brown spots with concentric rings and yellow halos,Apply chlorothalonil fungicides
37
+ Tomato___Tomato_Yellow_Leaf_Curl_Virus,Tomato___Tomato_Yellow_Leaf_Curl_Virus,Upward curling leaves with yellow margins,"Control whiteflies, remove infected plants"
38
+ Tomato___Tomato_mosaic_virus,Tomato___Tomato_mosaic_virus,Mottled light and dark green patterns,"Destroy infected plants, disinfect tools"
39
+ Tomato___healthy,Tomato___healthy,No visible disease symptoms,Rotate crops annually
plant_disease_data.py ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Disease Classes
2
+
3
+ class_name = ['Apple___Apple_scab',
4
+ 'Apple___Black_rot',
5
+ 'Apple___Cedar_apple_rust',
6
+ 'Apple___healthy',
7
+ 'Blueberry___healthy',
8
+ 'Cherry_(including_sour)___Powdery_mildew',
9
+ 'Cherry_(including_sour)___healthy',
10
+ 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot',
11
+ 'Corn_(maize)___Common_rust_',
12
+ 'Corn_(maize)___Northern_Leaf_Blight',
13
+ 'Corn_(maize)___healthy',
14
+ 'Grape___Black_rot',
15
+ 'Grape___Esca_(Black_Measles)',
16
+ 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)',
17
+ 'Grape___healthy',
18
+ 'Orange___Haunglongbing_(Citrus_greening)',
19
+ 'Peach___Bacterial_spot',
20
+ 'Peach___healthy',
21
+ 'Pepper,_bell___Bacterial_spot',
22
+ 'Pepper,_bell___healthy',
23
+ 'Potato___Early_blight',
24
+ 'Potato___Late_blight',
25
+ 'Potato___healthy',
26
+ 'Raspberry___healthy',
27
+ 'Soybean___healthy',
28
+ 'Squash___Powdery_mildew',
29
+ 'Strawberry___Leaf_scorch',
30
+ 'Strawberry___healthy',
31
+ 'Tomato___Bacterial_spot',
32
+ 'Tomato___Early_blight',
33
+ 'Tomato___Late_blight',
34
+ 'Tomato___Leaf_Mold',
35
+ 'Tomato___Septoria_leaf_spot',
36
+ 'Tomato___Spider_mites Two-spotted_spider_mite',
37
+ 'Tomato___Target_Spot',
38
+ 'Tomato___Tomato_Yellow_Leaf_Curl_Virus',
39
+ 'Tomato___Tomato_mosaic_virus',
40
+ 'Tomato___healthy']
41
+
42
+ # Disease Symptoms and Treatment
43
+
44
+ disease_db = {
45
+ "Apple___Apple_scab": {
46
+ "symptoms": "Olive-green to black spots on leaves, may cause leaf drop",
47
+ "treatment": "Apply fungicides like myclobutanil, prune affected branches"
48
+ },
49
+ "Apple___Black_rot": {
50
+ "symptoms": "Brown spots with concentric rings, shriveled fruits",
51
+ "treatment": "Remove infected plant material, apply captan fungicide"
52
+ },
53
+ "Apple___Cedar_apple_rust": {
54
+ "symptoms": "Yellow-orange spots on leaves, gelatinous growths",
55
+ "treatment": "Remove nearby junipers, apply fungicides in early spring"
56
+ },
57
+ "Apple___healthy": {
58
+ "symptoms": "No visible disease symptoms",
59
+ "treatment": "Maintain proper watering and fertilization"
60
+ },
61
+ "Blueberry___healthy": {
62
+ "symptoms": "No visible disease symptoms",
63
+ "treatment": "Ensure acidic soil conditions and proper pruning"
64
+ },
65
+ "Cherry_(including_sour)___Powdery_mildew": {
66
+ "symptoms": "White powdery spots on leaves and shoots",
67
+ "treatment": "Apply sulfur or potassium bicarbonate fungicides"
68
+ },
69
+ "Cherry_(including_sour)___healthy": {
70
+ "symptoms": "No visible disease symptoms",
71
+ "treatment": "Maintain good air circulation around trees"
72
+ },
73
+ "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot": {
74
+ "symptoms": "Rectangular tan lesions with dark borders on leaves",
75
+ "treatment": "Rotate crops, use resistant varieties"
76
+ },
77
+ "Corn_(maize)___Common_rust_": {
78
+ "symptoms": "Small, round to elongate golden brown pustules",
79
+ "treatment": "Apply fungicides at first sign of disease"
80
+ },
81
+ "Corn_(maize)___Northern_Leaf_Blight": {
82
+ "symptoms": "Long, elliptical gray-green lesions",
83
+ "treatment": "Use resistant hybrids, practice crop rotation"
84
+ },
85
+ "Corn_(maize)___healthy": {
86
+ "symptoms": "No visible disease symptoms",
87
+ "treatment": "Maintain proper plant spacing"
88
+ },
89
+ "Grape___Black_rot": {
90
+ "symptoms": "Brown leaf spots with black fruiting bodies",
91
+ "treatment": "Apply fungicides before flowering, remove infected berries"
92
+ },
93
+ "Grape___Esca_(Black_Measles)": {
94
+ "symptoms": "Tiger-stripe patterns on leaves, wood decay",
95
+ "treatment": "Prune affected wood, apply wound protectants"
96
+ },
97
+ "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)": {
98
+ "symptoms": "Angular brown spots with yellow halos",
99
+ "treatment": "Apply copper-based fungicides"
100
+ },
101
+ "Grape___healthy": {
102
+ "symptoms": "No visible disease symptoms",
103
+ "treatment": "Maintain proper trellising and pruning"
104
+ },
105
+ "Orange___Haunglongbing_(Citrus_greening)": {
106
+ "symptoms": "Yellow shoots, lopsided bitter fruit",
107
+ "treatment": "Remove infected trees, control psyllid vectors"
108
+ },
109
+ "Peach___Bacterial_spot": {
110
+ "symptoms": "Dark, angular leaf spots, fruit cracking",
111
+ "treatment": "Apply copper sprays during dormancy"
112
+ },
113
+ "Peach___healthy": {
114
+ "symptoms": "No visible disease symptoms",
115
+ "treatment": "Prune to improve air circulation"
116
+ },
117
+ "Pepper,_bell___Bacterial_spot": {
118
+ "symptoms": "Small water-soaked spots that turn brown",
119
+ "treatment": "Use disease-free seed, apply copper sprays"
120
+ },
121
+ "Pepper,_bell___healthy": {
122
+ "symptoms": "No visible disease symptoms",
123
+ "treatment": "Avoid overhead watering"
124
+ },
125
+ "Potato___Early_blight": {
126
+ "symptoms": "Small brown spots with target-like rings",
127
+ "treatment": "Rotate crops, apply chlorothalonil fungicides"
128
+ },
129
+ "Potato___Late_blight": {
130
+ "symptoms": "Greasy-looking dark lesions that spread quickly",
131
+ "treatment": "Destroy infected plants, use copper fungicides"
132
+ },
133
+ "Potato___healthy": {
134
+ "symptoms": "No visible disease symptoms",
135
+ "treatment": "Hill soil around plants"
136
+ },
137
+ "Raspberry___healthy": {
138
+ "symptoms": "No visible disease symptoms",
139
+ "treatment": "Remove old canes after fruiting"
140
+ },
141
+ "Soybean___healthy": {
142
+ "symptoms": "No visible disease symptoms",
143
+ "treatment": "Rotate with non-legume crops"
144
+ },
145
+ "Squash___Powdery_mildew": {
146
+ "symptoms": "White powdery coating on leaves",
147
+ "treatment": "Apply sulfur or horticultural oil"
148
+ },
149
+ "Strawberry___Leaf_scorch": {
150
+ "symptoms": "Purple spots with white centers on leaves",
151
+ "treatment": "Remove infected leaves, improve air flow"
152
+ },
153
+ "Strawberry___healthy": {
154
+ "symptoms": "No visible disease symptoms",
155
+ "treatment": "Renew beds every 2-3 years"
156
+ },
157
+ "Tomato___Bacterial_spot": {
158
+ "symptoms": "Small water-soaked spots with yellow halos",
159
+ "treatment": "Use pathogen-free seed, apply copper sprays"
160
+ },
161
+ "Tomato___Early_blight": {
162
+ "symptoms": "Dark spots with concentric rings on lower leaves",
163
+ "treatment": "Remove affected leaves, apply copper-based fungicides"
164
+ },
165
+ "Tomato___Late_blight": {
166
+ "symptoms": "Water-soaked lesions that turn brown and spread rapidly",
167
+ "treatment": "Destroy infected plants, use chlorothalonil fungicides"
168
+ },
169
+ "Tomato___Leaf_Mold": {
170
+ "symptoms": "Yellow spots with olive-green undersides",
171
+ "treatment": "Reduce humidity, apply fungicides"
172
+ },
173
+ "Tomato___Septoria_leaf_spot": {
174
+ "symptoms": "Small circular spots with dark borders",
175
+ "treatment": "Remove lower leaves, apply copper fungicides"
176
+ },
177
+ "Tomato___Spider_mites Two-spotted_spider_mite": {
178
+ "symptoms": "Fine webbing, stippled yellow leaves",
179
+ "treatment": "Apply miticides, increase humidity"
180
+ },
181
+ "Tomato___Target_Spot": {
182
+ "symptoms": "Brown spots with concentric rings and yellow halos",
183
+ "treatment": "Apply chlorothalonil fungicides"
184
+ },
185
+ "Tomato___Tomato_Yellow_Leaf_Curl_Virus": {
186
+ "symptoms": "Upward curling leaves with yellow margins",
187
+ "treatment": "Control whiteflies, remove infected plants"
188
+ },
189
+ "Tomato___Tomato_mosaic_virus": {
190
+ "symptoms": "Mottled light and dark green patterns",
191
+ "treatment": "Destroy infected plants, disinfect tools"
192
+ },
193
+ "Tomato___healthy": {
194
+ "symptoms": "No visible disease symptoms",
195
+ "treatment": "Rotate crops annually"
196
+ }
197
+ }
198
+
199
+ # class_name index is same as disease_db index
200
+
201
+ import csv
202
+ with open('plant_disease_data.csv', 'w', newline='') as f:
203
+ writer = csv.writer(f)
204
+ writer.writerow(["Class Name", "Disease", "Symptoms", "Treatment"])
205
+
206
+ for disease in class_name:
207
+ info = disease_db[disease]
208
+ writer.writerow([disease, disease, info["symptoms"], info["treatment"]])
209
+
210
+ # the result is a CSV with all diseases
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ tensorflow==2.10.0
2
+ scikit-learn==1.3.0
3
+ numpy==1.24.3
4
+ matplotlib==3.7.2
5
+ pandas==2.1.0
6
+ seaborn==0.13.0
7
+ streamlit