# !pip install timm # !pip install transformers # !pip install pillow from PIL import Image import gradio as gr # Use a pipeline as a high-level helper # object_detector = pipeline("object-detection", model="facebook/detr-resnet-50") # raw_image = Image .open("/content/dogwithman.jpg") # output = object_detector(raw_image) # print(output) from PIL import Image import gradio as gr from transformers import pipeline # Initialize the object detection pipeline object_detector = pipeline("object-detection", model="facebook/detr-resnet-50") def detect_objects(image): # Perform object detection on the input image results = object_detector(image) # Prepare the output string output = [] for result in results: label = result['label'] score = result['score'] box = result['box'] output.append(f"Label: {label}, Score: {score:.2f}, Box: {box}") return "\n".join(output) # Create the Gradio interface interface = gr.Interface( fn=detect_objects, inputs=gr.Image(type="pil"), outputs="text", title="Image Object Detector", description="Upload an image to detect objects using the DETR model." ) # Launch the app interface.launch()