Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import matplotlib.patches as patches
|
3 |
+
from matplotlib.patches import Patch
|
4 |
+
import io
|
5 |
+
from PIL import Image, ImageDraw58655
|
6 |
+
import numpy as np
|
7 |
+
import csv
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
from torchvision import transforms
|
11 |
+
|
12 |
+
from transformers import AutoModelForObjectDetection
|
13 |
+
import torch
|
14 |
+
|
15 |
+
import easyocr
|
16 |
+
|
17 |
+
import gradio as gr
|
18 |
+
|
19 |
+
|
20 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
+
|
22 |
+
def process_pdf():
|
23 |
+
print('process_pdf')
|
24 |
+
# cropped_table = detect_and_crop_table(image)
|
25 |
+
# image, cells = recognize_table(cropped_table)
|
26 |
+
|
27 |
+
# cell_coordinates = get_cell_coordinates_by_row(cells)
|
28 |
+
# df, data = apply_ocr(cell_coordinates, image)
|
29 |
+
|
30 |
+
# return image, df, data
|
31 |
+
return [], [], []
|
32 |
+
|
33 |
+
title = "Sheriff's Demo: Table Detection & Recognition with Table Transformer (TATR)."
|
34 |
+
description = """A demo by M Sheriff for table extraction with the Table Transformer.
|
35 |
+
First, table detection is performed on the input image using https://huggingface.co/microsoft/table-transformer-detection,
|
36 |
+
after which the detected table is extracted and https://huggingface.co/microsoft/table-transformer-structure-recognition-v1.1-all recognizes the
|
37 |
+
individual rows, columns and cells. OCR is then performed per cell, row by row."""
|
38 |
+
examples = [['image.png'], ['mistral_paper.png']]
|
39 |
+
|
40 |
+
app = gr.Interface(fn=process_pdf,
|
41 |
+
inputs=gr.Image(type="pil"),
|
42 |
+
outputs=[gr.Image(type="pil", label="Detected table"), gr.Dataframe(label="Table as CSV"), gr.JSON(label="Data as JSON")],
|
43 |
+
title=title,
|
44 |
+
description=description,
|
45 |
+
examples=examples)
|
46 |
+
app.queue()
|
47 |
+
app.launch(debug=True)
|