Update app.py
Browse files
app.py
CHANGED
|
@@ -58,10 +58,15 @@ def detect_objects(image, target_class, confidence_threshold, hf_token=None):
|
|
| 58 |
results = object_detector.detect(image, hf_token)
|
| 59 |
|
| 60 |
# Filter results for target class
|
|
|
|
| 61 |
target_detections = []
|
| 62 |
for detection in results:
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
target_detections.append(detection)
|
| 66 |
|
| 67 |
return target_detections
|
|
|
|
| 58 |
results = object_detector.detect(image, hf_token)
|
| 59 |
|
| 60 |
# Filter results for target class
|
| 61 |
+
|
| 62 |
target_detections = []
|
| 63 |
for detection in results:
|
| 64 |
+
label = detection.get('label')
|
| 65 |
+
if (
|
| 66 |
+
label is not None and
|
| 67 |
+
label.lower() == target_class.lower() and
|
| 68 |
+
detection['score'] > confidence_threshold
|
| 69 |
+
):
|
| 70 |
target_detections.append(detection)
|
| 71 |
|
| 72 |
return target_detections
|