Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from ultralytics.utils.plotting import Annotator
|
| 5 |
+
|
| 6 |
+
model_path = 'yolov10n_cs2.pt'
|
| 7 |
+
model = YOLO(model_path, task="detect")
|
| 8 |
+
|
| 9 |
+
def predict(image):
|
| 10 |
+
global model
|
| 11 |
+
results = model.predict(image, save=True)
|
| 12 |
+
annotator = Annotator(image)
|
| 13 |
+
for r in results:
|
| 14 |
+
boxes = r.boxes
|
| 15 |
+
for box in boxes:
|
| 16 |
+
b = box.xyxy[0]
|
| 17 |
+
c = box.cls
|
| 18 |
+
annotator.box_label(b, model.names[int(c)])
|
| 19 |
+
image = annotator.result()
|
| 20 |
+
return image
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
gr.Interface(
|
| 24 |
+
title="Detect players",
|
| 25 |
+
fn=predict,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Image(type="pil", label="Load image"),
|
| 28 |
+
],
|
| 29 |
+
outputs=gr.Image(type="pil", label="Detected players"),
|
| 30 |
+
).launch()
|