Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from PIL import Image
|
|
@@ -22,7 +23,6 @@ def predict(image):
|
|
| 22 |
|
| 23 |
if class_confidences:
|
| 24 |
lines = []
|
| 25 |
-
# Sort classes by their max confidence (highest first)
|
| 26 |
sorted_classes = sorted(
|
| 27 |
class_confidences.items(),
|
| 28 |
key=lambda x: max(x[1]),
|
|
@@ -30,17 +30,11 @@ def predict(image):
|
|
| 30 |
)
|
| 31 |
|
| 32 |
for class_name, confidences in sorted_classes:
|
| 33 |
-
|
| 34 |
-
avg_conf = round(sum(confidences) / count, 2)
|
| 35 |
max_conf = round(max(confidences), 2)
|
| 36 |
-
|
| 37 |
-
if count > 1:
|
| 38 |
-
lines.append(f"• {class_name} ({count}x) — avg: {avg_conf}% | best: {max_conf}%")
|
| 39 |
-
else:
|
| 40 |
-
lines.append(f"• {class_name} — {max_conf}%")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
result_text = f"Detected {total} object(s) in {len(class_confidences)} class(es):\n\n" + "\n".join(lines)
|
| 44 |
else:
|
| 45 |
result_text = "No detection"
|
| 46 |
|
|
@@ -57,4 +51,5 @@ demo = gr.Interface(
|
|
| 57 |
title="YOLOv8 Detection",
|
| 58 |
description="Upload an image and detect objects"
|
| 59 |
)
|
| 60 |
-
demo.launch()
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
import gradio as gr
|
| 3 |
from ultralytics import YOLO
|
| 4 |
from PIL import Image
|
|
|
|
| 23 |
|
| 24 |
if class_confidences:
|
| 25 |
lines = []
|
|
|
|
| 26 |
sorted_classes = sorted(
|
| 27 |
class_confidences.items(),
|
| 28 |
key=lambda x: max(x[1]),
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
for class_name, confidences in sorted_classes:
|
| 33 |
+
avg_conf = round(sum(confidences) / len(confidences), 2)
|
|
|
|
| 34 |
max_conf = round(max(confidences), 2)
|
| 35 |
+
lines.append(f"• {class_name} — avg: {avg_conf}% | best: {max_conf}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
result_text = "\n".join(lines)
|
|
|
|
| 38 |
else:
|
| 39 |
result_text = "No detection"
|
| 40 |
|
|
|
|
| 51 |
title="YOLOv8 Detection",
|
| 52 |
description="Upload an image and detect objects"
|
| 53 |
)
|
| 54 |
+
demo.launch()
|
| 55 |
+
```
|