File size: 770 Bytes
28753cb
 
 
 
 
db223bc
28753cb
 
 
 
 
 
bed362e
28753cb
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import torch
from PIL import Image
import pandas as pd

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

def inference(im):
    results = model(im)
    results._run(render=True)
    text = results.pandas().xyxy[0].round(2)
    counts = text.groupby(['name'])['name'].count()
    return Image.fromarray(results.ims[0]),str(counts)[5:-24]

title = "Count Objects in the picture"
description = "Count objects in picture by Yolov5s model" 
Example=[['test.jpg']]
demo = gr.Interface(inference,
        inputs = [gr.Image(label="Original Image")], 
        outputs = [gr.Image(label="Output Image"),gr.Textbox(label="Count Objects")], 
        title=title, 
        examples=Example,
        description=description)
demo.launch()