tjxj commited on
Commit
0cf52a1
·
1 Parent(s): 5b58521

Add application file

Browse files
.history/app_20220620143944.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #-*- coding : utf-8-*-
2
+
3
+ import pandas as pd
4
+ import streamlit as st
5
+ import base64
6
+ import subprocess # process in the os
7
+ from subprocess import STDOUT #os process manipuation
8
+ import os
9
+ import camelot as cam # extracting tables from PDFs
10
+
11
+ @st.cache
12
+ def gh():
13
+ """install ghostscript on the linux machine"""
14
+ proc = subprocess.Popen('apt-get install -y ghostscript', shell=True, stdin=None, stdout=open(os.devnull,"wb"), stderr=STDOUT, executable="/bin/bash")
15
+ proc.wait()
16
+
17
+ gh()
18
+ st.title("PDF Table Extractor")
19
+
20
+ input_pdf = st.file_uploader(label = "", type = 'pdf')
21
+
22
+ page_number = st.text_input("请填写表格所在PDF页码,eg: 3", value = 1)
23
+
24
+ if input_pdf is not None:
25
+ # byte object into a PDF file
26
+ with open("input.pdf", "wb") as f:
27
+ base64_pdf = base64.b64encode(input_pdf.read()).decode('utf-8')
28
+ f.write(base64.b64decode(base64_pdf))
29
+ f.close()
30
+
31
+ # read the pdf and parse it using stream
32
+ tables = cam.read_pdf("input.pdf", pages=page_number)
33
+ result = pd.ExcelWriter('result.xlsx', engine='xlsxwriter')
34
+ tables[0].to_excel(result,index=False)
35
+ # for i in range(0,len(tables)):
36
+ # table = tables[i].df
37
+ # sheetname = str(i)
38
+ # table.to_excel(result, sheetname,index=False)
39
+
40
+ with open('result.xlsx','rb') as f:
41
+ st.download_button('提取完成,点击下载!', f,file_name='result.xlsx',mime="application/vnd.ms-excel")
.history/app_20220620150505.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #-*- coding : utf-8-*-
2
+
3
+ import pandas as pd
4
+ import streamlit as st
5
+ import base64
6
+ import subprocess # process in the os
7
+ from subprocess import STDOUT #os process manipuation
8
+ import os
9
+
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
+ import camelot as cam # extracting tables from PDFs
18
+
19
+ st.title("PDF Table Extractor")
20
+
21
+ input_pdf = st.file_uploader(label = "", type = 'pdf')
22
+
23
+ page_number = st.text_input("请填写表格所在PDF页码,eg: 3", value = 1)
24
+
25
+ if input_pdf is not None:
26
+ # byte object into a PDF file
27
+ with open("input.pdf", "wb") as f:
28
+ base64_pdf = base64.b64encode(input_pdf.read()).decode('utf-8')
29
+ f.write(base64.b64decode(base64_pdf))
30
+ f.close()
31
+
32
+ # read the pdf and parse it using stream
33
+ tables = cam.read_pdf("input.pdf", pages=page_number)
34
+ result = pd.ExcelWriter('result.xlsx', engine='xlsxwriter')
35
+ tables[0].to_excel(result,index=False)
36
+ # for i in range(0,len(tables)):
37
+ # table = tables[i].df
38
+ # sheetname = str(i)
39
+ # table.to_excel(result, sheetname,index=False)
40
+
41
+ with open('result.xlsx','rb') as f:
42
+ st.download_button('提取完成,点击下载!', f,file_name='result.xlsx',mime="application/vnd.ms-excel")
app.py CHANGED
@@ -6,7 +6,6 @@ import base64
6
  import subprocess # process in the os
7
  from subprocess import STDOUT #os process manipuation
8
  import os
9
- import camelot as cam # extracting tables from PDFs
10
 
11
  @st.cache
12
  def gh():
@@ -15,6 +14,8 @@ def gh():
15
  proc.wait()
16
 
17
  gh()
 
 
18
  st.title("PDF Table Extractor")
19
 
20
  input_pdf = st.file_uploader(label = "", type = 'pdf')
 
6
  import subprocess # process in the os
7
  from subprocess import STDOUT #os process manipuation
8
  import os
 
9
 
10
  @st.cache
11
  def gh():
 
14
  proc.wait()
15
 
16
  gh()
17
+ import camelot as cam # extracting tables from PDFs
18
+
19
  st.title("PDF Table Extractor")
20
 
21
  input_pdf = st.file_uploader(label = "", type = 'pdf')