aryan365 commited on
Commit
fd2b59c
·
verified ·
1 Parent(s): 9a43fd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
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
- # Extract the detected classes
50
- class_indices = results[0].boxes.cls.cpu().numpy().astype(int) # Get the class indices
51
- unique_classes = np.unique(class_indices) # Get unique classes detected
52
-
53
- # Map class indices to labels if needed
54
- # Assuming you have a mapping for YOLO classes
55
- detected_classes = [str(cls) for cls in unique_classes]
 
 
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.85]
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