Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,42 +5,33 @@ from PIL import ImageDraw
|
|
5 |
|
6 |
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
|
7 |
|
8 |
-
# model_path = "C:\\Users\\abdul\\Documents\\genaiproj\\genai\\Models\\models--facebook--detr-resnet-50\\snapshots\\1d5f47bd3bdd2c4bbfa585418ffe6da5028b4c0b"
|
9 |
-
# object_detector = pipeline("object-detection", model=model_path) pc kk
|
10 |
-
|
11 |
def draw_bounding_boxes(image, detections):
|
12 |
draw = ImageDraw.Draw(image)
|
13 |
|
14 |
for detection in detections:
|
15 |
-
# Extract bounding box coordinates and label
|
16 |
box = detection['box']
|
17 |
label = detection['label']
|
18 |
xmin, ymin, xmax, ymax = box['xmin'], box['ymin'], box['xmax'], box['ymax']
|
19 |
|
20 |
-
# Draw rectangle and label
|
21 |
draw.rectangle([xmin, ymin, xmax, ymax], outline="red", width=3)
|
22 |
draw.text((xmin, ymin - 10), label, fill="red")
|
23 |
|
24 |
return image
|
25 |
|
26 |
-
|
27 |
def detect_object(image):
|
28 |
-
output = object_detector(raw_image
|
29 |
-
processed_image = draw_bounding_boxes(
|
30 |
return processed_image
|
31 |
|
32 |
-
# print(output)
|
33 |
-
|
34 |
gr.close_all()
|
35 |
|
36 |
-
# demo = gr.Interface(fn=summary, inputs="text", outputs="text")
|
37 |
-
|
38 |
demo = gr.Interface(
|
39 |
fn=detect_object,
|
40 |
inputs=[gr.Image(label="Select Image", type="pil")],
|
41 |
outputs=[gr.Image(label="Image with Bounding Box", type="pil")],
|
42 |
title="Object Detector",
|
43 |
theme="soft",
|
44 |
-
description="This is an object detection model that detects objects in an image and draws bounding boxes around them."
|
45 |
-
|
46 |
-
|
|
|
|
5 |
|
6 |
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
|
7 |
|
|
|
|
|
|
|
8 |
def draw_bounding_boxes(image, detections):
|
9 |
draw = ImageDraw.Draw(image)
|
10 |
|
11 |
for detection in detections:
|
|
|
12 |
box = detection['box']
|
13 |
label = detection['label']
|
14 |
xmin, ymin, xmax, ymax = box['xmin'], box['ymin'], box['xmax'], box['ymax']
|
15 |
|
|
|
16 |
draw.rectangle([xmin, ymin, xmax, ymax], outline="red", width=3)
|
17 |
draw.text((xmin, ymin - 10), label, fill="red")
|
18 |
|
19 |
return image
|
20 |
|
|
|
21 |
def detect_object(image):
|
22 |
+
output = object_detector(image) # Use 'image' instead of 'raw_image'
|
23 |
+
processed_image = draw_bounding_boxes(image.copy(), output) # Make a copy to avoid modifying the original
|
24 |
return processed_image
|
25 |
|
|
|
|
|
26 |
gr.close_all()
|
27 |
|
|
|
|
|
28 |
demo = gr.Interface(
|
29 |
fn=detect_object,
|
30 |
inputs=[gr.Image(label="Select Image", type="pil")],
|
31 |
outputs=[gr.Image(label="Image with Bounding Box", type="pil")],
|
32 |
title="Object Detector",
|
33 |
theme="soft",
|
34 |
+
description="This is an object detection model that detects objects in an image and draws bounding boxes around them."
|
35 |
+
)
|
36 |
+
|
37 |
+
demo.launch(share=True)
|