Spaces:
Sleeping
Sleeping
File size: 1,372 Bytes
13bcf5a aee21f5 13bcf5a aee21f5 13bcf5a aee21f5 13bcf5a aee21f5 0783d58 aee21f5 13bcf5a aee21f5 13bcf5a aee21f5 13bcf5a aee21f5 c7aa0d4 aee21f5 cdea0e4 aee21f5 13bcf5a aee21f5 c7aa0d4 13bcf5a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from transformers import pipeline
from helper import render_results_in_image, summarize_predictions_natural_language, ignore_warnings
# Suppress non-critical warnings
ignore_warnings()
# Load DETR object detection pipeline with lower threshold
pipe = pipeline("object-detection", model="facebook/detr-resnet-50", threshold=0.3)
# Function to get predictions and process image + summary
def get_pipeline_prediction(pil_image):
pipeline_output = pipe(pil_image)
if not pipeline_output:
return pil_image, "No objects detected."
processed_image = render_results_in_image(pil_image, pipeline_output)
summary = summarize_predictions_natural_language(pipeline_output)
return processed_image, summary
# Gradio interface
iface = gr.Interface(
fn=get_pipeline_prediction,
inputs=gr.Image(label="Upload an Image", type="pil"),
outputs=[
gr.Image(label="Image with Detected Objects", type="pil"),
gr.Textbox(label="Summary of Detected Objects")
],
examples=[
["examples/kittens.jpeg"],
["examples/beach.jpeg"]
],
title="Object Detection with DETR",
description="Upload an image to detect objects. Bounding boxes will be drawn and a natural language summary will be provided.",
flagging_mode="never"
)
if __name__ == "__main__":
iface.launch()
|