pierreguillou commited on
Commit
ac86f55
1 Parent(s): ad083b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -3,6 +3,9 @@ os.system('pip install "git+https://github.com/facebookresearch/detectron2.git@v
3
  import layoutparser as lp
4
  import gradio as gr
5
 
 
 
 
6
  # PubLayNet
7
  model1 = lp.Detectron2LayoutModel('lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config')
8
  model2 = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_R_50_FPN_3x/config')
@@ -10,31 +13,33 @@ model3 = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/c
10
 
11
  def lpi(img):
12
  # You need to load the image somewhere else, e.g., image = cv2.imread(...)
 
13
  layout1 = model1.detect(img)
14
  layout2 = model2.detect(img)
15
  layout3 = model3.detect(img)
16
 
 
17
  img1 = lp.draw_box(img, layout1)
18
  img2 = lp.draw_box(img, layout2)
19
  img3 = lp.draw_box(img, layout3)
20
 
21
- return img1, img2, img3 # With extra configurations
22
 
23
  inputs = gr.inputs.Image(type='pil', label="Original Image")
24
  outputs = [
25
- gr.outputs.Image(type="pil",label="Output Image (faster_rcnn_R_50_FPN_3x)"),
26
- gr.outputs.Image(type="pil",label="Output Image (mask_rcnn_R_50_FPN_3x)"),
27
- gr.outputs.Image(type="pil",label="Output Image (mask_rcnn_X_101_32x8d_FPN_3x)")
 
28
  ]
29
 
30
- title = "Layout Parser (PubLayNet models)"
31
- description = "demo for Layout Parser with PubLayNet models. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
32
  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>"
33
 
34
  examples = [
35
  ['example-table.jpeg'],
36
  ['paper-image.jpeg']
37
-
38
  ]
39
 
40
  gr.Interface(lpi, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()
 
3
  import layoutparser as lp
4
  import gradio as gr
5
 
6
+ # PrimaLayout
7
+ model0 = lp.Detectron2LayoutModel('lp://PrimaLayout/mask_rcnn_R_50_FPN_3x/config')
8
+
9
  # PubLayNet
10
  model1 = lp.Detectron2LayoutModel('lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config')
11
  model2 = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_R_50_FPN_3x/config')
 
13
 
14
  def lpi(img):
15
  # You need to load the image somewhere else, e.g., image = cv2.imread(...)
16
+ layout0 = model0.detect(img)
17
  layout1 = model1.detect(img)
18
  layout2 = model2.detect(img)
19
  layout3 = model3.detect(img)
20
 
21
+ img0 = lp.draw_box(img, layout0)
22
  img1 = lp.draw_box(img, layout1)
23
  img2 = lp.draw_box(img, layout2)
24
  img3 = lp.draw_box(img, layout3)
25
 
26
+ return img0, img1, img2, img3 # With extra configurations
27
 
28
  inputs = gr.inputs.Image(type='pil', label="Original Image")
29
  outputs = [
30
+ gr.outputs.Image(type="pil",label="Output Image (PrimaLayout/faster_rcnn_R_50_FPN_3x)"),
31
+ gr.outputs.Image(type="pil",label="Output Image (PubLayNet/faster_rcnn_R_50_FPN_3x)"),
32
+ gr.outputs.Image(type="pil",label="Output Image (PubLayNet/mask_rcnn_R_50_FPN_3x)"),
33
+ gr.outputs.Image(type="pil",label="Output Image (PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x)")
34
  ]
35
 
36
+ title = "Layout Parser (PrimaLayout & PubLayNet models)"
37
+ 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."
38
  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>"
39
 
40
  examples = [
41
  ['example-table.jpeg'],
42
  ['paper-image.jpeg']
 
43
  ]
44
 
45
  gr.Interface(lpi, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()