Solab commited on
Commit
17dc25e
·
1 Parent(s): 6bf2772

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +60 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # data app development
2
+ import subprocess # process in the os
3
+ from subprocess import STDOUT, check_call #os process manipulation
4
+ import os #os proces manipulation
5
+ import base64 # byte object into a pdf file
6
+ import camelot as cam # extracting tables from PDFs
7
+
8
+
9
+ # to run this only once it's cached
10
+ @st.cache
11
+ def gh():
12
+ """ install ghostscript on the linux machine"""
13
+ proc = subprocess.Popen('apt-get install -y ghostscript', shell=True, stdin=None, stdout=open(os.devnull, "wb",), stderr=STDOUT, executable="/bin/bash")
14
+ proc.wait()
15
+
16
+ gh()
17
+
18
+
19
+ st.title("PDF Table Extractor")
20
+ st.subheader("with `Camelot` python library")
21
+
22
+ st.image("https://raw.githubusercontent.com/camelot-dev/camelot/master/docs/_static/camelot.png", width=200)
23
+
24
+
25
+ # file uploader on streamlit
26
+ input_pdf = st.file_uploader(label = "upload your pdf here", type = 'pdf')
27
+
28
+ st.markdown("### Page Number")
29
+
30
+ page_number = st.text_input("Enter the page # from where you want to extract the PDF eg: 3", value = 1)
31
+
32
+ # run this only when the pdf is uploaded
33
+
34
+ if input_pdf is not None:
35
+ #byte object into a PDF file
36
+ with open("input.pdf", "wb") as f:
37
+ base64_pdf = base64.b64encode(input_pdf.read()).decode('utf-8')
38
+ f.write(base64.b64encode(base64_pdf))
39
+ f.close()
40
+
41
+ # read the pdf and parse it using stream
42
+ table = cam.read_pdf("input.pdf", pages=page_number, flavor='stream')
43
+
44
+ st.markdown("### Number of Tables")
45
+
46
+ # display the output of the table
47
+
48
+ st.write(table)
49
+
50
+ # display the table
51
+
52
+ if len(table) > 0:
53
+ # extract the index value of the table
54
+ option = st.selectbox(label="Select the table to be displayed", options = range(len(table) + 1))
55
+
56
+ st.markdown('### Output Table')
57
+
58
+ # display the dataframe
59
+
60
+ st.dataframe(table[int(option)-1].df)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ opencv-python-headless
2
+ camelot-py
3
+ streamlit