CoolFace
Apppublic

akhaliq/layout-parser

sourceHugging Faceupdated 4y agoView on Hugging Face
3likes
app.py25 linesDownload Raw Back to root
1import os2os.system('pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"')3import layoutparser as lp4import gradio as gr5 6model = lp.Detectron2LayoutModel('lp://PrimaLayout/mask_rcnn_R_50_FPN_3x/config')7 8def lpi(img):9  layout = model.detect(img) # You need to load the image somewhere else, e.g., image = cv2.imread(...)10  return lp.draw_box(img, layout,) # With extra configurations11 12inputs = gr.inputs.Image(type='pil', label="Original Image")13outputs = gr.outputs.Image(type="pil",label="Output Image")14 15title = "Layout Parser"16description = "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."17article = "<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>"18 19examples = [20    ['example-table.jpeg'],21    ['paper-image.jpeg']22 23]24 25gr.Interface(lpi, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()