YonaniCodes commited on
Commit
c1390ae
Β·
1 Parent(s): 40848b2
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -18,6 +18,9 @@ def load_breeds(file_path=class_file_path):
18
 
19
  labels = load_breeds()
20
 
 
 
 
21
  def process_image(image, img_size=224):
22
  img_array = tf.keras.preprocessing.image.img_to_array(image)
23
  img_array = tf.image.resize(img_array, [img_size, img_size]) / 255.0
@@ -26,7 +29,7 @@ def process_image(image, img_size=224):
26
  def predict_breed(image):
27
  try:
28
  if image is None:
29
- return "❌ No image uploaded. Please upload a Maize or Tomato leaf image.", {}
30
 
31
  img_array = process_image(image)
32
  img_array = tf.expand_dims(img_array, axis=0)
@@ -36,7 +39,7 @@ def predict_breed(image):
36
 
37
  top_pred_class = labels[top3_indices[0]]
38
  if "maize" not in top_pred_class.lower() and "tomato" not in top_pred_class.lower():
39
- return "❌ This model only supports Maize and Tomato leaf images.", {}
40
 
41
  output_lines = ["🌿 **Top 3 Predictions:**"]
42
  confidence_scores = {}
@@ -47,16 +50,20 @@ def predict_breed(image):
47
  output_lines.append(f"{class_name}: {confidence:.2f}%")
48
  confidence_scores[class_name] = float(f"{confidence:.2f}")
49
 
50
- return "\n".join(output_lines), confidence_scores
51
 
52
  except Exception as e:
53
  print("Prediction Error:", e)
54
- return "❌ File not supported. Please upload a valid image file (JPEG/PNG).", {}
55
 
56
  interface = gr.Interface(
57
  fn=predict_breed,
58
  inputs=gr.Image(type="pil", label="Upload Maize or Tomato Leaf Image"),
59
- outputs=[gr.Text(label="Prediction"), gr.Label(label="Confidence Scores")],
 
 
 
 
60
  title="🌿 Hares: Maize & Tomato Disease Classifier",
61
  description="Upload an image of a maize or tomato leaf to identify possible diseases.",
62
  )
 
18
 
19
  labels = load_breeds()
20
 
21
+ # Prepare disease list text
22
+ disease_list_text = "**Supported Diseases:**\n\n" + "\n".join([label.replace('_', ' ').title() for label in labels])
23
+
24
  def process_image(image, img_size=224):
25
  img_array = tf.keras.preprocessing.image.img_to_array(image)
26
  img_array = tf.image.resize(img_array, [img_size, img_size]) / 255.0
 
29
  def predict_breed(image):
30
  try:
31
  if image is None:
32
+ return "❌ No image uploaded. Please upload a Maize or Tomato leaf image.", {}, disease_list_text
33
 
34
  img_array = process_image(image)
35
  img_array = tf.expand_dims(img_array, axis=0)
 
39
 
40
  top_pred_class = labels[top3_indices[0]]
41
  if "maize" not in top_pred_class.lower() and "tomato" not in top_pred_class.lower():
42
+ return "❌ This model only supports Maize and Tomato leaf images.", {}, disease_list_text
43
 
44
  output_lines = ["🌿 **Top 3 Predictions:**"]
45
  confidence_scores = {}
 
50
  output_lines.append(f"{class_name}: {confidence:.2f}%")
51
  confidence_scores[class_name] = float(f"{confidence:.2f}")
52
 
53
+ return "\n".join(output_lines), confidence_scores, disease_list_text
54
 
55
  except Exception as e:
56
  print("Prediction Error:", e)
57
+ return "❌ File not supported. Please upload a valid image file (JPEG/PNG).", {}, disease_list_text
58
 
59
  interface = gr.Interface(
60
  fn=predict_breed,
61
  inputs=gr.Image(type="pil", label="Upload Maize or Tomato Leaf Image"),
62
+ outputs=[
63
+ gr.Text(label="Prediction"),
64
+ gr.Label(label="Confidence Scores"),
65
+ gr.Markdown(label="Supported Diseases")
66
+ ],
67
  title="🌿 Hares: Maize & Tomato Disease Classifier",
68
  description="Upload an image of a maize or tomato leaf to identify possible diseases.",
69
  )