Spaces:
Build error
Build error
Upload 4 files
Browse files- .gitattributes +1 -0
- app.py +76 -0
- model.keras +3 -0
- plant_disease_data.csv +39 -0
- 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
|
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
|