File size: 1,156 Bytes
3c6aae1
 
a24e845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53a2e8a
 
a24e845
 
 
 
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
import os
os.system('pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"')
import layoutparser as lp
import gradio as gr

model = lp.Detectron2LayoutModel('lp://PrimaLayout/mask_rcnn_R_50_FPN_3x/config')

def lpi(img):
  layout = model.detect(img) # You need to load the image somewhere else, e.g., image = cv2.imread(...)
  return lp.draw_box(img, layout,) # With extra configurations

inputs = gr.inputs.Image(type='pil', label="Original Image")
outputs = gr.outputs.Image(type="pil",label="Output Image")

title = "Layout Parser"
description = "demo for Layout Parser. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2103.15348'>LayoutParser: A Unified Toolkit for Deep Learning Based Document Image Analysis</a> | <a href='https://github.com/Layout-Parser/layout-parser'>Github Repo</a></p>"

examples = [
    ['example-table.jpeg'],
    ['paper-image.jpeg']

]

gr.Interface(lpi, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()