Update app.py
Browse files
app.py
CHANGED
|
@@ -45,14 +45,16 @@ def predict():
|
|
| 45 |
|
| 46 |
# Perform inference using the YOLO model
|
| 47 |
results = model(image) # Pass the image to the YOLO model
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
|
| 57 |
return jsonify({'predictions': detected_classes})
|
| 58 |
except Exception as e:
|
|
@@ -105,7 +107,7 @@ def ocr():
|
|
| 105 |
# Perform text detection using YOLO
|
| 106 |
results = model(image)
|
| 107 |
detections = results[0].boxes
|
| 108 |
-
high_conf_detections = [box for box in detections if box.conf > 0.
|
| 109 |
|
| 110 |
# Check if there are any high-confidence detections
|
| 111 |
text_present = len(high_conf_detections) > 0
|
|
|
|
| 45 |
|
| 46 |
# Perform inference using the YOLO model
|
| 47 |
results = model(image) # Pass the image to the YOLO model
|
| 48 |
+
detections = results[0].boxes
|
| 49 |
+
detected_vegetables = []
|
| 50 |
+
for box in detections:
|
| 51 |
+
if box.conf > CONFIDENCE_THRESHOLD:
|
| 52 |
+
class_index = int(box.cls[0].item()) # Get class index as an integer
|
| 53 |
+
|
| 54 |
+
# Use model's class names dynamically
|
| 55 |
+
vegetable_name = model.names[class_index] # Get the name directly from the model
|
| 56 |
+
detected_vegetables.append(vegetable_name)
|
| 57 |
+
detected_classes=detected_vegetables[0]
|
| 58 |
|
| 59 |
return jsonify({'predictions': detected_classes})
|
| 60 |
except Exception as e:
|
|
|
|
| 107 |
# Perform text detection using YOLO
|
| 108 |
results = model(image)
|
| 109 |
detections = results[0].boxes
|
| 110 |
+
high_conf_detections = [box for box in detections if box.conf > 0.55]
|
| 111 |
|
| 112 |
# Check if there are any high-confidence detections
|
| 113 |
text_present = len(high_conf_detections) > 0
|