Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pandas as pd
|
|
| 5 |
import torch
|
| 6 |
import json
|
| 7 |
from ultralytics import YOLO
|
|
|
|
| 8 |
|
| 9 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 10 |
# print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
|
@@ -14,26 +15,31 @@ print(f"Is CUDA available: {torch.cuda.is_available()}")
|
|
| 14 |
detect_model = YOLO('yolov8m_2023-10-23_best.pt')
|
| 15 |
|
| 16 |
def detect(image):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
title = "🐢"
|
| 39 |
|
|
|
|
| 5 |
import torch
|
| 6 |
import json
|
| 7 |
from ultralytics import YOLO
|
| 8 |
+
from datetime import datetime
|
| 9 |
|
| 10 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 11 |
# print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
|
|
|
| 15 |
detect_model = YOLO('yolov8m_2023-10-23_best.pt')
|
| 16 |
|
| 17 |
def detect(image):
|
| 18 |
+
results = detect_model(image, conf=0.1)
|
| 19 |
+
# Get the current time
|
| 20 |
+
current_time = datetime.now()
|
| 21 |
+
# Format the current time as a string
|
| 22 |
+
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
| 23 |
+
print(formatted_time)
|
| 24 |
+
try:
|
| 25 |
+
results = results[0].boxes.xyxy[0].cpu().numpy()
|
| 26 |
+
top = int(results[1])
|
| 27 |
+
left = int(results[0])
|
| 28 |
+
width = int(results[2] - results[0])
|
| 29 |
+
height = int(results[3] - results[1])
|
| 30 |
+
return {
|
| 31 |
+
"top": top,
|
| 32 |
+
"left": left,
|
| 33 |
+
"width": width,
|
| 34 |
+
"height": height
|
| 35 |
+
}
|
| 36 |
+
except:
|
| 37 |
+
return {
|
| 38 |
+
"top": 0,
|
| 39 |
+
"left": 0,
|
| 40 |
+
"width": 0,
|
| 41 |
+
"height": 0
|
| 42 |
+
}
|
| 43 |
|
| 44 |
title = "🐢"
|
| 45 |
|