File size: 1,455 Bytes
705d051
 
 
 
 
 
 
 
 
 
 
 
 
e40a6f6
705d051
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from PIL import Image, ImageDraw
import yolov5
import json

model = yolov5.load("./best.pt")

def yolo(im):

    results = model(im)  # inference

    df = results.pandas().xyxy[0].to_json(orient="records")

    res = json.loads(df)

    draw = ImageDraw.Draw(im)

    for bb in res:
        xmin = bb['xmin']
        ymin = bb['ymin']
        xmax = bb['xmax']
        ymax = bb['ymax']
        draw.rectangle([xmin, ymin, xmax, ymax], outline="red", width=3)

    return [
        res,
        im,
    ]


inputs = gr.Image(type='pil', label="Original Image")
outputs = [
    gr.JSON(label="Output JSON"),
    gr.Image(type='pil', label="Output Image with Boxes"),
]

title = "YOLOv5 Character"
description = "YOLOv5 Character Gradio demo for object detection. Upload an image or click an example image to use."
article = "<p style='text-align: center'>YOLOv5 Character is an object detection model trained on the <a href=\"http://codh.rois.ac.jp/char-shape/\">日本古典籍くずし字データセット</a>.</p>"

examples = [
    ['『源氏物語』(東京大学総合図書館所蔵).jpg'],
    ['『源氏物語』(京都大学所蔵).jpg'],
    ['『平家物語』(国文学研究資料館提供).jpg']
]
demo = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples)

demo.css = """
.json-holder {
    height: 300px;
    overflow: auto;
}
"""

demo.launch(share=False)