File size: 862 Bytes
962aa5c
c775630
 
 
962aa5c
c775630
962aa5c
c775630
 
 
decd62f
c775630
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import streamlit as st
from img2table.document import PDF
from img2table.ocr import TesseractOCR

st.title("Image to Table")

uploaded_file = st.file_uploader("Choose a file")
page_number = st.number_input("Page number", value=1, min_value=1)
submit = st.button("Submit")

if submit and uploaded_file is not None and page_number is not None:
    pdf = PDF(uploaded_file, pages=[page_number-1])
    ocr = TesseractOCR(lang="eng")
    pdf_tables = pdf.extract_tables(ocr)
    st.write(pdf_tables)
    pdf.to_xlsx("output.xlsx", ocr=ocr)
    with open("output.xlsx", "rb") as file:
        btn = st.download_button(
                label="Download Excel",
                data=file,
                file_name="output.xlsx",
                mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
    os.remove("output.xlsx")