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