Spaces:
Runtime error
Runtime error
File size: 1,329 Bytes
447b47e 43eb482 d83daa9 43eb482 447b47e d83daa9 9b1be63 43eb482 4d48b95 43eb482 4d48b95 d83daa9 43eb482 d83daa9 43eb482 447b47e 43eb482 4d48b95 447b47e 43eb482 2417fbd 43eb482 447b47e 2417fbd |
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 |
import gradio as gr
from PIL import Image
import yolov5
import json
model = yolov5.load("nakamura196/yolov5-ndl-layout")
def yolo(im):
results = model(im) # inference
df = results.pandas().xyxy[0].to_json(orient="records")
res = json.loads(df)
im_with_boxes = results.render()[0] # results.render() returns a list of images
# Convert the numpy array back to an image
output_image = Image.fromarray(im_with_boxes)
return [
output_image,
res
]
inputs = gr.Image(type='pil', label="Original Image")
outputs = [
gr.Image(type="pil", label="Output Image"),
gr.JSON()
]
title = "YOLOv5 NDL-DocL Datasets"
description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."
article = "<p style='text-align: center'>YOLOv5 NDL-DocL Datasets is an object detection model trained on the <a href=\"https://github.com/ndl-lab/layout-dataset\">NDL-DocL Datasets</a>.</p>"
examples = [
['『源氏物語』(東京大学総合図書館所蔵).jpg'],
['『源氏物語』(京都大学所蔵).jpg'],
['『平家物語』(国文学研究資料館提供).jpg']
]
demo = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples)
demo.launch(share=False) |