Spaces:
Runtime error
Runtime error
work on plotting code
Browse files
app.py
CHANGED
@@ -5,8 +5,24 @@ from gradio.components import Image, Radio, Textbox
|
|
5 |
|
6 |
|
7 |
def plot_bounding_boxes(image, boxes, box_type):
|
|
|
|
|
|
|
8 |
x0, y0, x1, y1 = [int(i.strip()) for i in boxes.split(",")]
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
detections = sv.Detections(
|
11 |
xyxy=np.array([[x0, y0, x1, y1]]),
|
12 |
class_id=np.array([0]),
|
@@ -27,7 +43,7 @@ iface = gr.Interface(
|
|
27 |
fn=plot_bounding_boxes,
|
28 |
inputs=[
|
29 |
Image(type="pil", label="Image"),
|
30 |
-
Textbox(label="Bounding
|
31 |
Radio(["xyxy", "xywh"], label="Bounding Box Type"),
|
32 |
],
|
33 |
outputs=Image(type="pil"),
|
|
|
5 |
|
6 |
|
7 |
def plot_bounding_boxes(image, boxes, box_type):
|
8 |
+
if not boxes:
|
9 |
+
return image
|
10 |
+
|
11 |
x0, y0, x1, y1 = [int(i.strip()) for i in boxes.split(",")]
|
12 |
|
13 |
+
image_width = image.size[0]
|
14 |
+
image_height = image.size[1]
|
15 |
+
|
16 |
+
if box_type == "xywh":
|
17 |
+
x1 = x0 + x1
|
18 |
+
y1 = y0 + y1
|
19 |
+
|
20 |
+
x0 = x0 * image_width
|
21 |
+
x1 = x1 * image_width
|
22 |
+
|
23 |
+
y0 = y0 * image_height
|
24 |
+
y1 = y1 * image_height
|
25 |
+
|
26 |
detections = sv.Detections(
|
27 |
xyxy=np.array([[x0, y0, x1, y1]]),
|
28 |
class_id=np.array([0]),
|
|
|
43 |
fn=plot_bounding_boxes,
|
44 |
inputs=[
|
45 |
Image(type="pil", label="Image"),
|
46 |
+
Textbox(label="Bounding Box (separate values by comma, like '100, 200, 300, 400')", lines=3),
|
47 |
Radio(["xyxy", "xywh"], label="Bounding Box Type"),
|
48 |
],
|
49 |
outputs=Image(type="pil"),
|