Spaces:
Runtime error
Runtime error
File size: 1,495 Bytes
ff1c40c | 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 | from transformers import pipeline
from transformers.utils import logging
from helper import load_image_from_url, render_results_in_image
from PIL import Image
import gradio as gr
import os
# Reduce the verbosity of transformers and suppress warnings
logging.set_verbosity_error()
# Load the object detection pipeline
od_pipe = pipeline("object-detection", "facebook/detr-resnet-50")
def get_pipeline_prediction(pil_image):
# Perform object detection
pipeline_output = od_pipe(pil_image)
# Render results on the image
processed_image = render_results_in_image(pil_image, pipeline_output)
return processed_image
# Custom CSS to improve the interface
css = """
body { font-family: Arial, sans-serif; }
button { background-color: #4CAF50; color: white; border: none; padding: 10px 20px; }
"""
# Set up the Gradio Blocks interface
with gr.Blocks(css=css) as demo:
gr.Markdown("## Object Detection Service")
gr.Markdown("Upload an image and see the object detection results rendered on the image.")
with gr.Row():
image_input = gr.Image(label="Upload Image", type="pil", tool="editor")
submit_button = gr.Button("Detect Objects")
output_image = gr.Image(label="Detected Objects")
submit_button.click(
get_pipeline_prediction,
inputs=[image_input],
outputs=[output_image]
)
# Launch the Gradio app
demo.launch(share=True, server_port=int(os.environ.get('PORT1', 7860))) # Default port 7860 if PORT1 is not set
|