Ahsen Khaliq commited on
Commit
a24e845
1 Parent(s): 22b2178

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import layoutparser as lp
2
+ import gradio as gr
3
+
4
+ model = lp.Detectron2LayoutModel('lp://PrimaLayout/mask_rcnn_R_50_FPN_3x/config')
5
+
6
+ def lpi(img):
7
+ layout = model.detect(img) # You need to load the image somewhere else, e.g., image = cv2.imread(...)
8
+ return lp.draw_box(img, layout,) # With extra configurations
9
+
10
+ inputs = gr.inputs.Image(type='pil', label="Original Image")
11
+ outputs = gr.outputs.Image(type="pil",label="Output Image")
12
+
13
+ title = "Layout Parser"
14
+ 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."
15
+ 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>"
16
+
17
+ examples = [
18
+ ['examples/data/example-table.jpeg'],
19
+ ['examples/data/paper-image.jpg']
20
+
21
+ ]
22
+
23
+ gr.Interface(lpi, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()