File size: 737 Bytes
062a5d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator

model_path = 'yolov10n_cs2.pt'
model = YOLO(model_path, task="detect")

def predict(image):
    global model
    results = model.predict(image, save=True)
    annotator = Annotator(image)
    for r in results:
        boxes = r.boxes
        for box in boxes:
            b = box.xyxy[0]
            c = box.cls
            annotator.box_label(b, model.names[int(c)])
    image = annotator.result()
    return image


gr.Interface(
    title="Detect players",
    fn=predict,
    inputs=[
        gr.Image(type="pil", label="Load image"),
    ],
    outputs=gr.Image(type="pil", label="Detected players"),
).launch()