isana25 commited on
Commit
4f88f01
·
verified ·
1 Parent(s): 5a5c33c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -5,6 +5,15 @@ from PIL import Image
5
  # Load YOLOv5 model
6
  model = YOLO("best.pt") # make sure best.pt is in the same directory
7
 
 
 
 
 
 
 
 
 
 
8
  # Prediction function
9
  def predict(image):
10
  results = model(image)
@@ -17,18 +26,13 @@ def predict(image):
17
  else:
18
  for box in boxes:
19
  class_id = int(box.cls[0])
20
- full_label = names[class_id]
21
  confidence = float(box.conf[0])
 
 
22
 
23
- # Split label into plant and disease
24
- if "___" in full_label:
25
- plant_name, disease_name = full_label.split("___")
26
- else:
27
- plant_name = "Unknown"
28
- disease_name = full_label
29
-
30
- output += f"🌿 Plant: {plant_name}\n"
31
  output += f"⚠️ Disease: {disease_name}\n"
 
32
  output += f"🔍 Confidence: {confidence * 100:.2f}%\n\n"
33
 
34
  return output.strip()
@@ -38,5 +42,5 @@ gr.Interface(
38
  inputs=gr.Image(type="pil"),
39
  outputs="text",
40
  title="🌿 AgroScan: Plant Disease Detector",
41
- description="Upload a plant leaf image to detect disease and identify the plant.",
42
  ).launch()
 
5
  # Load YOLOv5 model
6
  model = YOLO("best.pt") # make sure best.pt is in the same directory
7
 
8
+ # You can define a simple disease severity mapping like this:
9
+ disease_severity = {
10
+ "Late_blight": "High",
11
+ "Early_blight": "Medium",
12
+ "Powdery_mildew": "Low",
13
+ "Healthy": "None",
14
+ # Add your disease names and severity levels here accordingly
15
+ }
16
+
17
  # Prediction function
18
  def predict(image):
19
  results = model(image)
 
26
  else:
27
  for box in boxes:
28
  class_id = int(box.cls[0])
29
+ disease_name = names[class_id]
30
  confidence = float(box.conf[0])
31
+
32
+ severity = disease_severity.get(disease_name, "Unknown")
33
 
 
 
 
 
 
 
 
 
34
  output += f"⚠️ Disease: {disease_name}\n"
35
+ output += f"❗ Seriousness Level: {severity}\n"
36
  output += f"🔍 Confidence: {confidence * 100:.2f}%\n\n"
37
 
38
  return output.strip()
 
42
  inputs=gr.Image(type="pil"),
43
  outputs="text",
44
  title="🌿 AgroScan: Plant Disease Detector",
45
+ description="Upload a plant leaf image to detect disease and get disease seriousness and confidence.",
46
  ).launch()