Update app.py
Browse filesImprove UX in case no prompted object detected
app.py
CHANGED
|
@@ -46,7 +46,7 @@ def detect_objects(image_url, uploaded_image, text_prompt):
|
|
| 46 |
results = processor.post_process_grounded_object_detection(
|
| 47 |
outputs,
|
| 48 |
inputs.input_ids,
|
| 49 |
-
threshold=0.
|
| 50 |
target_sizes=[image.size[::-1]]
|
| 51 |
)
|
| 52 |
|
|
@@ -76,13 +76,14 @@ def detect_objects(image_url, uploaded_image, text_prompt):
|
|
| 76 |
draw.text((x1, max(0, y1 - 15)), f"{label} {score:.2f}", fill="red")
|
| 77 |
|
| 78 |
if not detected_labels:
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
Try:
|
| 83 |
-
- lowering the threshold
|
| 84 |
-
- using a clearer image
|
| 85 |
- changing the detection prompt
|
|
|
|
|
|
|
| 86 |
""", image
|
| 87 |
|
| 88 |
counts = Counter(detected_labels)
|
|
|
|
| 46 |
results = processor.post_process_grounded_object_detection(
|
| 47 |
outputs,
|
| 48 |
inputs.input_ids,
|
| 49 |
+
threshold=0.25,
|
| 50 |
target_sizes=[image.size[::-1]]
|
| 51 |
)
|
| 52 |
|
|
|
|
| 76 |
draw.text((x1, max(0, y1 - 15)), f"{label} {score:.2f}", fill="red")
|
| 77 |
|
| 78 |
if not detected_labels:
|
| 79 |
+
searched_object = text_prompt.strip().rstrip(".")
|
| 80 |
+
return f"""
|
| 81 |
+
# No "{searched_object}" detected
|
| 82 |
|
| 83 |
Try:
|
|
|
|
|
|
|
| 84 |
- changing the detection prompt
|
| 85 |
+
- using a clearer image
|
| 86 |
+
- lowering the threshold
|
| 87 |
""", image
|
| 88 |
|
| 89 |
counts = Counter(detected_labels)
|