Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,25 @@
|
|
1 |
-
import tabula
|
2 |
-
import pandas as pd
|
3 |
-
import streamlit as st
|
4 |
import os
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
st.title("TableOCR")
|
9 |
-
|
10 |
-
st.markdown(
|
11 |
-
"""
|
12 |
-
<style>
|
13 |
-
.css-1jc7ptx, .e1ewe7hr3, .viewerBadge_container__1QSob,
|
14 |
-
.styles_viewerBadge__1yB5_, .viewerBadge_link__1S137,
|
15 |
-
.viewerBadge_text__1JaDK {
|
16 |
-
display: none;
|
17 |
-
}
|
18 |
-
</style>
|
19 |
-
""",
|
20 |
-
unsafe_allow_html=True
|
21 |
-
)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
submit_button = st.form_submit_button(label='Submit')
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
+
from img2table.document import PDF
|
4 |
+
from img2table.ocr import TesseractOCR
|
5 |
|
6 |
+
st.title("Image to Table")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
uploaded_file = st.file_uploader("Choose a file")
|
9 |
+
page_number = st.number_input("Page number", value=1, min_value=1)
|
10 |
+
submit = st.button("Submit")
|
|
|
11 |
|
12 |
+
if submit and uploaded_file is not None and page_number is not None:
|
13 |
+
pdf = PDF(uploaded_file, pages=[page_number-1])
|
14 |
+
ocr = TesseractOCR(lang="eng")
|
15 |
+
pdf_tables = pdf.extract_tables(ocr)
|
16 |
+
st.write(pdf_tables)
|
17 |
+
pdf.to_xlsx("output.xlsx", ocr=ocr)
|
18 |
+
with open("output.xlsx", "rb") as file:
|
19 |
+
btn = st.download_button(
|
20 |
+
label="Download Excel",
|
21 |
+
data=file,
|
22 |
+
file_name="output.xlsx",
|
23 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
24 |
+
)
|
25 |
+
os.remove("output.xlsx")
|