Spaces:
Running
Running
Uploading Trashify box detection model app.py
Browse files
app.py
CHANGED
|
@@ -100,31 +100,32 @@ def predict_on_image(image, conf_threshold):
|
|
| 100 |
|
| 101 |
### 5. Create logic for outputting information message ###
|
| 102 |
|
| 103 |
-
# Setup blank string to print out
|
| 104 |
-
return_string = ""
|
| 105 |
-
|
| 106 |
# Setup set of target items to discover
|
| 107 |
target_items = {"trash", "bin", "hand"}
|
| 108 |
detected_items = set(detected_class_name_text_labels)
|
| 109 |
|
| 110 |
# If no items detected or trash, bin, hand not in detected items, return notification
|
| 111 |
if not detected_items & target_items:
|
| 112 |
-
return_string = (
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
print(return_string)
|
| 115 |
return image, return_string
|
| 116 |
|
| 117 |
# If there are missing items, say what the missing items are
|
| 118 |
missing_items = target_items - detected_items
|
| 119 |
if missing_items:
|
| 120 |
-
return_string = (
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
print(return_string)
|
| 124 |
return image, return_string
|
| 125 |
|
| 126 |
# If all target items are present (the final remaining case)
|
| 127 |
-
return_string = f"+1! Found the following items: {
|
| 128 |
print(return_string)
|
| 129 |
return image, return_string
|
| 130 |
|
|
|
|
| 100 |
|
| 101 |
### 5. Create logic for outputting information message ###
|
| 102 |
|
|
|
|
|
|
|
|
|
|
| 103 |
# Setup set of target items to discover
|
| 104 |
target_items = {"trash", "bin", "hand"}
|
| 105 |
detected_items = set(detected_class_name_text_labels)
|
| 106 |
|
| 107 |
# If no items detected or trash, bin, hand not in detected items, return notification
|
| 108 |
if not detected_items & target_items:
|
| 109 |
+
return_string = (
|
| 110 |
+
f"No trash, bin or hand detected at confidence threshold {conf_threshold}. "
|
| 111 |
+
"Try another image or lowering the confidence threshold."
|
| 112 |
+
)
|
| 113 |
print(return_string)
|
| 114 |
return image, return_string
|
| 115 |
|
| 116 |
# If there are missing items, say what the missing items are
|
| 117 |
missing_items = target_items - detected_items
|
| 118 |
if missing_items:
|
| 119 |
+
return_string = (
|
| 120 |
+
f"Detected the following items: {sorted(detected_items & target_items)}. But missing the following in order to get +1: {sorted(missing_items)}. "
|
| 121 |
+
"If this is an error, try another image or altering the confidence threshold. "
|
| 122 |
+
"Otherwise, the model may need to be updated with better data."
|
| 123 |
+
)
|
| 124 |
print(return_string)
|
| 125 |
return image, return_string
|
| 126 |
|
| 127 |
# If all target items are present (the final remaining case)
|
| 128 |
+
return_string = f"+1! Found the following items: {sorted(detected_items)}, thank you for cleaning up the area!"
|
| 129 |
print(return_string)
|
| 130 |
return image, return_string
|
| 131 |
|