Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from transformers import AutoProcessor, AutoModel
|
|
| 3 |
from PIL import Image
|
| 4 |
from pdf2image import convert_from_path
|
| 5 |
from PyPDF2 import PdfReader
|
|
|
|
| 6 |
|
| 7 |
# Load the LayoutLMv3 model and processor
|
| 8 |
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")
|
|
@@ -31,9 +32,10 @@ def process_image(image):
|
|
| 31 |
|
| 32 |
# Gradio interface function
|
| 33 |
def extract_table(file, page_number):
|
| 34 |
-
|
|
|
|
| 35 |
return process_pdf(file, page_number)
|
| 36 |
-
elif
|
| 37 |
image = Image.open(file)
|
| 38 |
return process_image(image)
|
| 39 |
else:
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from pdf2image import convert_from_path
|
| 5 |
from PyPDF2 import PdfReader
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
# Load the LayoutLMv3 model and processor
|
| 9 |
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")
|
|
|
|
| 32 |
|
| 33 |
# Gradio interface function
|
| 34 |
def extract_table(file, page_number):
|
| 35 |
+
file_ext = os.path.splitext(file.name)[1].lower()
|
| 36 |
+
if file_ext == ".pdf":
|
| 37 |
return process_pdf(file, page_number)
|
| 38 |
+
elif file_ext in [".png", ".jpg", ".jpeg"]:
|
| 39 |
image = Image.open(file)
|
| 40 |
return process_image(image)
|
| 41 |
else:
|