Nazia Nafis commited on
Commit
e9afe19
1 Parent(s): e942ebc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import subprocess
3
+ from subprocess import STDOUT, check_call
4
+ import os
5
+ import base64
6
+ import camelot as cam
7
+
8
+ @st.cache
9
+ def gh():
10
+ proc = subprocess.Popen('apt-get install -y ghostscript', shell=True, stdin=None, stdout=open(os.devnull,'wb'), stderr=STDOUT, executable="/bin/bash")
11
+
12
+ gh()
13
+
14
+ st.title("PDF Table Extractor")
15
+ st.subheader("with Camelot Python Library")
16
+
17
+ input_pdf = st.file_uploader(label="Upload PDF here",type='pdf')
18
+
19
+ st.markdown("### Page Number")
20
+
21
+ page_number = st.text_input("Enter the page # from where you want the table", value=1)
22
+
23
+ if input_pdf is not None:
24
+
25
+ with open("input.pdf","wb") as f:
26
+ base64_pdf = base64.b64encode(input_pdf.read()).decode('utf-8')
27
+ f.write(base64.b64decode(base64_pdf))
28
+ f.close()
29
+
30
+ table = cam.read_pdf("input.pdf",pages = page_number, flavor = 'stream')
31
+
32
+ st.markdown("## Number of Tables")
33
+
34
+ st.write(table)
35
+
36
+ if len(table)>0:
37
+
38
+ option = st.selectbox(label="Select the table to be displayed", options = range(len(table)+1))
39
+
40
+ st.markdown("### Output Table")
41
+
42
+ st.dataframe(table[int(option)-1].df)
43
+
44
+