File size: 2,053 Bytes
36d6867
 
 
 
 
ac86f55
 
 
67c6b29
ad083b6
 
 
36d6867
 
67c6b29
ac86f55
ad083b6
67c6b29
 
 
ac86f55
ad083b6
67c6b29
 
 
ac86f55
36d6867
 
b1e5912
ac86f55
 
 
 
b1e5912
36d6867
ac86f55
 
36d6867
 
 
 
 
 
 
 
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
import os
os.system('pip install "git+https://github.com/facebookresearch/[email protected]#egg=detectron2"')
import layoutparser as lp
import gradio as gr

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

# PubLayNet 	
model1 = lp.Detectron2LayoutModel('lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config')
model2 = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_R_50_FPN_3x/config')
model3 = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config')

def lpi(img):
  # You need to load the image somewhere else, e.g., image = cv2.imread(...)
  layout0 = model0.detect(img)
  layout1 = model1.detect(img) 
  layout2 = model2.detect(img)
  layout3 = model3.detect(img)
  
  img0 = lp.draw_box(img, layout0)
  img1 = lp.draw_box(img, layout1)
  img2 = lp.draw_box(img, layout2)
  img3 = lp.draw_box(img, layout3)
  
  return img0, img1, img2, img3 # With extra configurations

inputs = gr.inputs.Image(type='pil', label="Original Image")
outputs = [
gr.outputs.Image(type="pil",label="Output Image (PrimaLayout/faster_rcnn_R_50_FPN_3x)"),
gr.outputs.Image(type="pil",label="Output Image (PubLayNet/faster_rcnn_R_50_FPN_3x)"),
gr.outputs.Image(type="pil",label="Output Image (PubLayNet/mask_rcnn_R_50_FPN_3x)"),
gr.outputs.Image(type="pil",label="Output Image (PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x)")
]

title = "Layout Parser (PrimaLayout & PubLayNet models)"
description = "demo for Layout Parser with PrimaLayout & PubLayNet models. 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()