Rupesx007 commited on
Commit
2d5b077
·
verified ·
1 Parent(s): 8764169

uploaded necessary files

Browse files
class_indices.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"0": "Apple___Apple_scab", "1": "Apple___Black_rot", "2": "Apple___Cedar_apple_rust", "3": "Apple___healthy", "4": "Blueberry___healthy", "5": "Cherry_(including_sour)___Powdery_mildew", "6": "Cherry_(including_sour)___healthy", "7": "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", "8": "Corn_(maize)___Common_rust_", "9": "Corn_(maize)___Northern_Leaf_Blight", "10": "Corn_(maize)___healthy", "11": "Grape___Black_rot", "12": "Grape___Esca_(Black_Measles)", "13": "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)", "14": "Grape___healthy", "15": "Orange___Haunglongbing_(Citrus_greening)", "16": "Peach___Bacterial_spot", "17": "Peach___healthy", "18": "Pepper,_bell___Bacterial_spot", "19": "Pepper,_bell___healthy", "20": "Potato___Early_blight", "21": "Potato___Late_blight", "22": "Potato___healthy", "23": "Raspberry___healthy", "24": "Soybean___healthy", "25": "Squash___Powdery_mildew", "26": "Strawberry___Leaf_scorch", "27": "Strawberry___healthy", "28": "Tomato___Bacterial_spot", "29": "Tomato___Early_blight", "30": "Tomato___Late_blight", "31": "Tomato___Leaf_Mold", "32": "Tomato___Septoria_leaf_spot", "33": "Tomato___Spider_mites Two-spotted_spider_mite", "34": "Tomato___Target_Spot", "35": "Tomato___Tomato_Yellow_Leaf_Curl_Virus", "36": "Tomato___Tomato_mosaic_virus", "37": "Tomato___healthy"}
main.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ import pickle
6
+ import json
7
+
8
+ st.title("AI-based Crop Disease Detection and Recommendation System")
9
+
10
+ uploaded_image = st.file_uploader(label="Upload an Image")
11
+
12
+ # Function to Load and Preprocess the Image using Pillow
13
+ def load_and_preprocess_image(image_path, target_size=(224, 224)):
14
+ # Load the image
15
+ img = Image.open(image_path)
16
+ # Resize the image
17
+ img = img.resize(target_size)
18
+ # Convert the image to a numpy array
19
+ img_array = np.array(img)
20
+ # Add batch dimension
21
+ img_array = np.expand_dims(img_array, axis=0)
22
+ # Scale the image values to [0, 1]
23
+ img_array = img_array.astype('float32') / 255.
24
+ return img_array
25
+
26
+ # load the trained model
27
+ try:
28
+ model = tf.keras.models.load_model('plant_disease_prediction_model.h5')
29
+ except Exception as e:
30
+ st.error(f"Error Loading Model.", e)
31
+
32
+ # Load class indices
33
+ try:
34
+ with open('class_indices.json', 'r') as f:
35
+ class_indices = json.load(f)
36
+ except FileNotFoundError:
37
+ st.error("class_indices.json file not found")
38
+
39
+
40
+ recommendations = {
41
+ 'Apple___Apple_scab': 'Apply a fungicide that contains captan, copper, or sulfur. Remove infected leaves and fruit.',
42
+ 'Apple___Black_rot': 'Prune and destroy affected branches. Use a copper-based fungicide spray.',
43
+ 'Apple___Cedar_apple_rust': 'Remove nearby cedar trees if possible. Apply a fungicide during spring.',
44
+ 'Apple___healthy': 'Keep monitoring the crop and ensure optimal conditions for growth.',
45
+ 'Blueberry___healthy': 'Maintain good irrigation and nutrient levels.',
46
+ 'Cherry_(including_sour)___Powdery_mildew': 'Prune affected parts and apply a sulfur-based fungicide. Ensure proper air circulation around the plants.',
47
+ 'Cherry_(including_sour)___healthy': 'Regularly inspect for any early signs of disease and maintain optimal conditions.',
48
+ 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot': 'Apply fungicides with active ingredients like azoxystrobin or pyraclostrobin. Ensure crop rotation.',
49
+ 'Corn_(maize)___Common_rust_': 'Plant resistant varieties and apply fungicides containing mancozeb or chlorothalonil.',
50
+ 'Corn_(maize)___Northern_Leaf_Blight': 'Use resistant seed varieties and apply a triazole or strobilurin fungicide.',
51
+ 'Corn_(maize)___healthy': 'Maintain good agricultural practices, including adequate spacing and nutrient management.',
52
+ 'Grape___Black_rot': 'Remove and destroy infected leaves and fruit. Apply fungicides like mancozeb or myclobutanil.',
53
+ 'Grape___Esca_(Black_Measles)': 'Prune affected vines and use appropriate fungicides. Consider improving drainage and limiting stress on the plants.',
54
+ 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)': 'Prune infected areas and ensure proper airflow. Apply copper-based fungicides as needed.',
55
+ 'Grape___healthy': 'Ensure proper care, including balanced nutrition and regular monitoring.',
56
+ 'Orange___Haunglongbing_(Citrus_greening)': 'There is no cure; remove affected trees to prevent spreading. Implement vector control for psyllids.',
57
+ 'Peach___Bacterial_spot': 'Remove infected leaves and fruit. Apply copper-based bactericides and avoid overhead irrigation.',
58
+ 'Peach___healthy': 'Continue monitoring and maintain proper nutrition and watering practices.',
59
+ 'Pepper,_bell___Bacterial_spot': 'Remove and destroy infected leaves. Use copper-based bactericides and avoid overhead watering.',
60
+ 'Pepper,_bell___healthy': 'Maintain proper spacing and ensure good air circulation around plants.',
61
+ 'Potato___Early_blight': 'Apply fungicides like chlorothalonil or mancozeb. Practice crop rotation and use resistant varieties.',
62
+ 'Potato___Late_blight': 'Remove affected plants immediately and apply fungicides containing chlorothalonil or mancozeb.',
63
+ 'Potato___healthy': 'Keep monitoring and ensure proper soil management and nutrient levels.',
64
+ 'Raspberry___healthy': 'Ensure good practices such as regular weeding, proper spacing, and balanced fertilization.',
65
+ 'Soybean___healthy': 'Maintain proper soil health and use crop rotation practices to avoid diseases.',
66
+ 'Squash___Powdery_mildew': 'Apply sulfur-based fungicides and ensure good air circulation by pruning overcrowded areas.',
67
+ 'Strawberry___Leaf_scorch': 'Remove and destroy affected leaves. Apply a copper-based fungicide if necessary.',
68
+ 'Strawberry___healthy': 'Maintain proper irrigation practices and inspect regularly for early disease signs.',
69
+ 'Tomato___Bacterial_spot': 'Use copper-based sprays and avoid working in the garden when plants are wet to prevent spreading.',
70
+ 'Tomato___Early_blight': 'Use a fungicide with mancozeb or chlorothalonil. Remove and destroy affected foliage.',
71
+ 'Tomato___Late_blight': 'Remove and destroy affected plants to stop spreading. Apply chlorothalonil-based fungicides.',
72
+ 'Tomato___Leaf_Mold': 'Improve airflow around plants and apply fungicides with chlorothalonil or copper.',
73
+ 'Tomato___Septoria_leaf_spot': 'Remove affected leaves and use fungicides containing chlorothalonil or copper.',
74
+ 'Tomato___Spider_mites Two-spotted_spider_mite': 'Spray with insecticidal soap or neem oil. Ensure plants are well-hydrated.',
75
+ 'Tomato___Target_Spot': 'Apply a fungicide containing azoxystrobin and remove affected leaves.',
76
+ 'Tomato___Tomato_Yellow_Leaf_Curl_Virus': 'Control whitefly populations as they spread the virus. Remove infected plants promptly.',
77
+ 'Tomato___Tomato_mosaic_virus': 'Remove infected plants and disinfect tools. Plant virus-resistant varieties.',
78
+ 'Tomato___healthy': 'Ensure proper plant spacing and optimal watering practices to prevent diseases.'
79
+ }
80
+
81
+
82
+ # Predict the class of the uploaded image
83
+ if uploaded_image:
84
+ image_path = uploaded_image
85
+ preprocessed_image = load_and_preprocess_image(image_path)
86
+ predictions = model.predict(preprocessed_image)
87
+ predicted_class_index = np.argmax(predictions, axis=1)[0]
88
+
89
+ # Get the class name
90
+ predicted_class_name = class_indices.get(str(predicted_class_index), "Unknown")
91
+ recommended = recommendations.get(predicted_class_name, "No Recommendation Available!!")
92
+
93
+ st.write("The Predicted Class is:", predicted_class_name)
94
+ st.title("Recommendation")
95
+ st.info(recommended)
96
+ else:
97
+ st.text("Please upload an image.")
plant_disease_prediction_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e4b6f62e6a615eb8b7ed4392abb5fabf4b02be1748baf407af0337a03ff61b59
3
+ size 573701104