nnpy commited on
Commit
c775630
·
verified ·
1 Parent(s): 9735920

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -34
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
- os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-17-openjdk-amd64/bin/java"
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
- with st.form(key='my_form'):
24
- file = st.file_uploader("Upload a file", type="pdf", accept_multiple_files=False)
25
- page_no = st.number_input("Enter page number", min_value=1, value=1)
26
- submit_button = st.form_submit_button(label='Submit')
27
 
28
- if submit_button and file is not None and page_no is not None:
29
- with st.spinner("Converting PDF page to image..."):
30
- tables = tabula.read_pdf(file, pages=page_no, multiple_tables=True)
31
- table_df = tables[0] if tables else pd.DataFrame()
32
- st.write("Scroll down to download the output file.")
33
- st.table(table_df)
34
- table_df.to_excel("output.xlsx", index=False)
35
- st.markdown(
36
- f'<a href="output.xlsx" download="output.xlsx">Click here to download the output file</a>',
37
- unsafe_allow_html=True
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")