Vishaltiwari2019's picture
Update app.py
f70b16e verified
raw
history blame
912 Bytes
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()