Dishaa01423 commited on
Commit
cb6852d
1 Parent(s): 168dc89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -9
app.py CHANGED
@@ -9,7 +9,7 @@ from tensorflow.keras.models import load_model
9
  # Print versions for debugging
10
  st.write("TensorFlow version:", tf.__version__)
11
 
12
- # model
13
  out_len = 10 # Replace this with the actual number of output classes
14
 
15
  # Ensure no conflicts with 'model' or 'load_model'
@@ -24,12 +24,57 @@ except Exception as e:
24
 
25
  # Define the class names
26
  class_names = [
27
- 'Tomato_Bacterial_spot', 'Tomato_Early_blight', 'Tomato_Late_blight',
28
- 'Tomato_Leaf_Mold', 'Tomato_Septoria_leaf_spot', 'Tomato_Spider_mites_Two_spotted_spider_mite',
29
- 'Tomato_Target_Spot', 'Tomato_Tomato_Yellow_Leaf_Curl_Virus',
30
- 'Tomato_Tomato_mosaic_virus', 'Tomato_healthy'
 
31
  ]
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # Function to load and preprocess the image
34
  def load_and_prep_image(image):
35
  try:
@@ -53,17 +98,27 @@ if uploaded_file is not None:
53
  # Display the uploaded image
54
  image = Image.open(uploaded_file)
55
  st.image(image, caption='Uploaded Image', use_column_width=True)
56
-
57
  # Preprocess the image
58
  prepped_image = load_and_prep_image(image)
59
-
60
  # Ensure the model is loaded and image is preprocessed before making a prediction
61
  if VIT is not None and prepped_image is not None:
62
  # Make prediction
63
  prediction = VIT.predict(prepped_image)
64
  predicted_class = class_names[np.argmax(prediction)]
65
-
66
  # Display the prediction
67
  st.write(f"Prediction: {predicted_class}")
 
 
 
 
 
 
 
 
 
 
68
  except Exception as e:
69
- st.error(f"Error during prediction: {e}")
 
9
  # Print versions for debugging
10
  st.write("TensorFlow version:", tf.__version__)
11
 
12
+ # model
13
  out_len = 10 # Replace this with the actual number of output classes
14
 
15
  # Ensure no conflicts with 'model' or 'load_model'
 
24
 
25
  # Define the class names
26
  class_names = [
27
+ 'Tomato_Bacterial_spot', 'Tomato_Early_blight', 'Tomato_Late_blight',
28
+ 'Tomato_Leaf_Mold', 'Tomato_Septoria_leaf_spot',
29
+ 'Tomato_Spider_mites_Two_spotted_spider_mite', 'Tomato_Target_Spot',
30
+ 'Tomato_Tomato_Yellow_Leaf_Curl_Virus', 'Tomato_Tomato_mosaic_virus',
31
+ 'Tomato_healthy'
32
  ]
33
 
34
+ # Define cure and prevention suggestions for each disease
35
+ disease_info = {
36
+ 'Tomato_Bacterial_spot': {
37
+ 'cure': "Remove infected plants, use copper-based fungicides.",
38
+ 'prevention': "Use disease-free seeds, practice crop rotation, avoid overhead irrigation."
39
+ },
40
+ 'Tomato_Early_blight': {
41
+ 'cure': "Remove infected leaves, apply fungicides.",
42
+ 'prevention': "Mulch around plants, ensure good air circulation, water at the base of plants."
43
+ },
44
+ 'Tomato_Late_blight': {
45
+ 'cure': "Remove and destroy infected plants, apply fungicides.",
46
+ 'prevention': "Plant resistant varieties, avoid overhead watering, space plants properly."
47
+ },
48
+ 'Tomato_Leaf_Mold': {
49
+ 'cure': "Improve air circulation, apply fungicides.",
50
+ 'prevention': "Reduce humidity, avoid leaf wetness, use resistant varieties."
51
+ },
52
+ 'Tomato_Septoria_leaf_spot': {
53
+ 'cure': "Remove infected leaves, apply fungicides.",
54
+ 'prevention': "Mulch around plants, practice crop rotation, avoid overhead watering."
55
+ },
56
+ 'Tomato_Spider_mites_Two_spotted_spider_mite': {
57
+ 'cure': "Use insecticidal soaps or neem oil, introduce predatory mites.",
58
+ 'prevention': "Keep plants well-watered, increase humidity, use reflective mulches."
59
+ },
60
+ 'Tomato_Target_Spot': {
61
+ 'cure': "Remove infected leaves, apply fungicides.",
62
+ 'prevention': "Improve air circulation, avoid overhead watering, practice crop rotation."
63
+ },
64
+ 'Tomato_Tomato_Yellow_Leaf_Curl_Virus': {
65
+ 'cure': "No cure available, remove and destroy infected plants.",
66
+ 'prevention': "Use resistant varieties, control whiteflies, use reflective mulches."
67
+ },
68
+ 'Tomato_Tomato_mosaic_virus': {
69
+ 'cure': "No cure available, remove and destroy infected plants.",
70
+ 'prevention': "Use disease-free seeds, disinfect tools, control aphids."
71
+ },
72
+ 'Tomato_healthy': {
73
+ 'cure': "No treatment needed.",
74
+ 'prevention': "Maintain good gardening practices for overall plant health."
75
+ }
76
+ }
77
+
78
  # Function to load and preprocess the image
79
  def load_and_prep_image(image):
80
  try:
 
98
  # Display the uploaded image
99
  image = Image.open(uploaded_file)
100
  st.image(image, caption='Uploaded Image', use_column_width=True)
101
+
102
  # Preprocess the image
103
  prepped_image = load_and_prep_image(image)
104
+
105
  # Ensure the model is loaded and image is preprocessed before making a prediction
106
  if VIT is not None and prepped_image is not None:
107
  # Make prediction
108
  prediction = VIT.predict(prepped_image)
109
  predicted_class = class_names[np.argmax(prediction)]
110
+
111
  # Display the prediction
112
  st.write(f"Prediction: {predicted_class}")
113
+
114
+ # Display cure and prevention suggestions
115
+ if predicted_class in disease_info:
116
+ st.subheader("Cure:")
117
+ st.write(disease_info[predicted_class]['cure'])
118
+ st.subheader("Prevention:")
119
+ st.write(disease_info[predicted_class]['prevention'])
120
+ else:
121
+ st.write("No specific cure or prevention information available for this condition.")
122
+
123
  except Exception as e:
124
+ st.error(f"Error during prediction: {e}")