Spaces:
Runtime error
Runtime error
File size: 1,403 Bytes
c5343cf 39af238 2bbffd8 346c324 39af238 64424d9 48f78b9 64424d9 39af238 2bbffd8 39af238 346c324 39af238 8de5efe 39af238 5d1f4e2 39af238 df338e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
from PIL import Image
import numpy as np
import gradio as gr
import pandas as pd
import torch
import json
from ultralytics import YOLO
from datetime import datetime
print(f"Is CUDA available: {torch.cuda.is_available()}")
# print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
# Load the model
# detect_model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, _verbose=False)
detect_model = YOLO('yolov8m_2023-10-23_best.pt')
def detect(image):
results = detect_model(image, conf=0.1)
# Get the current time
current_time = datetime.now()
# Format the current time as a string
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print(formatted_time)
try:
results = results[0].boxes.xyxy[0].cpu().numpy()
top = int(results[1])
left = int(results[0])
width = int(results[2] - results[0])
height = int(results[3] - results[1])
return {
"top": top,
"left": left,
"width": width,
"height": height
}
except:
return {
"top": 0,
"left": 0,
"width": 0,
"height": 0
}
title = "🐢"
gr.Interface(
fn=detect,
inputs=gr.Image(type="pil", label="Input Image"),
outputs=[gr.JSON()],
# live=True,
title=title,
).launch() |