eskayML/object_detection_system
2
1import gradio as gr2import cv23from transformers import pipeline4 5model = pipeline('object-detection')6 7def draw_box(image):8 img = cv2.imread(image)9 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)10 test = model(image)11 12 for objects in test:13 if objects['score'] < .5:14 continue15 16 coord = objects['box']17 label = objects['label']18 color = (0,0,255)19 img = cv2.rectangle(img, (coord['xmin'],coord['ymin']) , (coord['xmax'],coord['ymax']), color,1 )20 img = cv2.putText(img,label,(coord['xmin'], coord['ymin']-10), cv2.FONT_HERSHEY_PLAIN, 1, color , 2)21 22 return img23 24 25with gr.Blocks() as demo:26 27 28 gr.Markdown("""# Object Detection using the Transformers library <br> 29 Enter an Image on the left and view the localized objects on the right.30 """)31 32 with gr.Row():33 inp = gr.Image( type='filepath')34 out = gr.Image()35 btn = gr.Button('Detect Objects')36 37 38 btn.click(fn = draw_box, inputs = inp, outputs = out)39 40demo.launch()41 42 43 