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