Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).cuda()
|
| 7 |
+
|
| 8 |
+
def inference(im):
|
| 9 |
+
results = model(im)
|
| 10 |
+
results._run(render=True)
|
| 11 |
+
text = results.pandas().xyxy[0].round(2)
|
| 12 |
+
counts = text.groupby(['name'])['name'].count()
|
| 13 |
+
return Image.fromarray(results.ims[0]),str(counts)[4:-20]
|
| 14 |
+
|
| 15 |
+
title = "Count Objects in the picture"
|
| 16 |
+
description = "Count objects in picture by Yolov5s model"
|
| 17 |
+
Example=[['test.jpg']]
|
| 18 |
+
demo = gr.Interface(inference,
|
| 19 |
+
inputs = [gr.Image(label="Original Image")],
|
| 20 |
+
outputs = [gr.Image(label="Output Image"),gr.Textbox(label="Count Objects")],
|
| 21 |
+
title=title,
|
| 22 |
+
examples=Example,
|
| 23 |
+
description=description)
|
| 24 |
+
demo.launch()
|
test.jpg
ADDED
|