Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load YOLOS pipeline
|
6 |
+
detector = pipeline("object-detection", model="hustvl/yolos-small")
|
7 |
+
|
8 |
+
def detect_objects(img):
|
9 |
+
results = detector(img)
|
10 |
+
boxes = []
|
11 |
+
for obj in results:
|
12 |
+
label = f"{obj['label']} ({obj['score']:.2f})"
|
13 |
+
box = obj['box']
|
14 |
+
boxes.append((box["xmin"], box["ymin"], box["xmax"], box["ymax"], label))
|
15 |
+
return img, boxes
|
16 |
+
|
17 |
+
demo = gr.Interface(
|
18 |
+
fn=detect_objects,
|
19 |
+
inputs=gr.Image(type="pil"),
|
20 |
+
outputs=gr.AnnotatedImage(),
|
21 |
+
title="YOLOS Object Detection",
|
22 |
+
description="Upload an image and detect objects using the YOLOS Transformer model.",
|
23 |
+
)
|
24 |
+
|
25 |
+
demo.launch()
|