Spaces:
Runtime error
Runtime error
add code
Browse files- app.py +35 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import supervision as sv
|
3 |
+
import numpy as np
|
4 |
+
from gradio.components import Image, Textbox, Radio
|
5 |
+
|
6 |
+
def plot_bounding_boxes(image, boxes, box_type):
|
7 |
+
x0, y0, x1, y1 = [int(i.strip()) for i in boxes.split(",")]
|
8 |
+
|
9 |
+
detections = sv.Detections(
|
10 |
+
xyxy=np.array([[x0, y0, x1, y1]]),
|
11 |
+
class_id=np.array([0]),
|
12 |
+
confidence=np.array([1.0]),
|
13 |
+
)
|
14 |
+
# convert to cv2
|
15 |
+
image = np.array(image)
|
16 |
+
|
17 |
+
bounding_box_annotator = sv.BoundingBoxAnnotator()
|
18 |
+
annotated_image = bounding_box_annotator.annotate(
|
19 |
+
scene=image, detections=detections)
|
20 |
+
|
21 |
+
return annotated_image
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=plot_bounding_boxes,
|
25 |
+
inputs=[
|
26 |
+
Image(type="pil", label="Image"),
|
27 |
+
Textbox(label="Bounding Boxes", lines=3, default="100,100,200,200"),
|
28 |
+
Radio(["xyxy", "xywh"], label="Bounding Box Type"),
|
29 |
+
],
|
30 |
+
outputs=Image(type="pil"),
|
31 |
+
title="Plot Bounding Boxes",
|
32 |
+
description="Plot bounding boxes on an image. Useful for testing object detection models without writing bounding box code. Powered by [supervision](https://github.com/roboflow/supervision)."
|
33 |
+
)
|
34 |
+
|
35 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
supervision
|