Spaces:
Sleeping
Sleeping
SarowarSaurav
commited on
Commit
•
6f2a51c
1
Parent(s):
29b03e2
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,8 @@ from PIL import Image
|
|
4 |
import numpy as np
|
5 |
import cv2
|
6 |
|
7 |
-
# Load the YOLOv8 model (
|
8 |
-
model = YOLO('yolov8n.pt')
|
9 |
|
10 |
def identify_disease(image):
|
11 |
# Convert the image to RGB if it's not
|
@@ -14,9 +14,18 @@ def identify_disease(image):
|
|
14 |
|
15 |
# Perform inference
|
16 |
results = model(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Extract predictions
|
19 |
-
predictions = results[0]
|
20 |
boxes = predictions.boxes
|
21 |
labels = boxes.cls.cpu().numpy()
|
22 |
scores = boxes.conf.cpu().numpy()
|
|
|
4 |
import numpy as np
|
5 |
import cv2
|
6 |
|
7 |
+
# Load the YOLOv8 model (ensure this path is correct)
|
8 |
+
model = YOLO('yolov8n.pt')
|
9 |
|
10 |
def identify_disease(image):
|
11 |
# Convert the image to RGB if it's not
|
|
|
14 |
|
15 |
# Perform inference
|
16 |
results = model(image)
|
17 |
+
predictions = results[0]
|
18 |
+
|
19 |
+
# Check if there are any detections
|
20 |
+
if len(predictions.boxes) == 0:
|
21 |
+
# No detections, return the image with a message
|
22 |
+
annotated_image = np.array(image)
|
23 |
+
cv2.putText(annotated_image, "No disease detected", (10, 30),
|
24 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
|
25 |
+
annotated_image = Image.fromarray(annotated_image)
|
26 |
+
return annotated_image, [{"Disease": "None", "Confidence": "N/A"}]
|
27 |
|
28 |
# Extract predictions
|
|
|
29 |
boxes = predictions.boxes
|
30 |
labels = boxes.cls.cpu().numpy()
|
31 |
scores = boxes.conf.cpu().numpy()
|