File size: 912 Bytes
d240e67
f70b16e
d240e67
f70b16e
 
d240e67
f70b16e
 
 
 
 
 
 
 
 
d240e67
f70b16e
 
 
d240e67
f70b16e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Load the DETR object detection pipeline
object_detection_pipeline = pipeline("object-detection", model="facebook/detr-resnet-50")

# Function to perform object detection on an image
def detect_objects(image):
    # Perform object detection
    results = object_detection_pipeline(image)
    # Extract bounding boxes and object labels
    bounding_boxes = [obj["bbox"] for obj in results]
    labels = [obj["label"] for obj in results]
    # Return bounding boxes and labels
    return bounding_boxes, labels

# Define Gradio interface
inputs = gr.inputs.Image()
outputs = gr.outputs.ObjectDetection(labels=["person", "car", "truck", "bicycle", "motorcycle"]) # Customize labels as needed

# Create Gradio interface
gr.Interface(fn=detect_objects, inputs=inputs, outputs=outputs, title="Object Detection", description="Detect objects in images.").launch()