Tzktz commited on
Commit
d89e475
1 Parent(s): c2e2733

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system('pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"')
3
+ import layoutparser as lp
4
+ import gradio as gr
5
+
6
+ # Initialize the Table Bank model for table detection
7
+ model_table_bank = lp.Detectron2LayoutModel('lp://TableBank/faster_rcnn_R_101_FPN_3x/config')
8
+
9
+
10
+ # Define the layout analysis function
11
+ def detect_tables(img):
12
+ tables_layout = model_table_bank.detect(img)
13
+ img_with_tables = lp.draw_box(img, tables_layout)
14
+ return img_with_tables
15
+
16
+
17
+ # Set up Gradio interface
18
+ inputs = gr.inputs.Image(type='pil', label="Original Image")
19
+ outputs = [gr.outputs.Image(type="pil", label="Output Image with Tables")]
20
+
21
+ title = "Table Detection with Layout Parser (Table Bank Model)"
22
+ css = ".output-image, .input-image, .image-preview {height: 600px !important}"
23
+
24
+ article = "<p style='text-align: center'><a href='https://github.com/Layout-Parser/layout-parser'>Layout Parser GitHub Repo</a></p>"
25
+
26
+ gr.Interface(detect_tables, inputs, outputs, title=title, article=article, css=css).launch()