Spaces:
Sleeping
Sleeping
Create app.py
Browse files12345678910111213141516171819202122232425import gradio as grfrom transformers import pipeline
# Initialize the object detection pipeline with the microsoft/table-transformer-detection modelpipe = pipeline("object-detection", model="microsoft/table-transformer-detection")
# Define the function to detect objects in an imagedef detect_objects(image): result = pipe(image) # Format the result to show detected objects and their scores detections = [{"label": item["label"], "score": item["score"], "box": item["box"]} for item in result] return detections
# Set up the Gradio interfaceapp = gr.Interface( fn=detect_objects, # Function for object detection inputs=gr.Image(type="filepath"), # Input field to upload an image outputs=gr.JSON(), # Output field for detected objects (JSON format) title="Object Detection", # Title of the app description="Upload an image to detect objects using Microsoft's Table Transformer model.")
# Launch the appif __name__ == "__main__": app.launch()app.pyAdded+25