Spaces:
Runtime error
Runtime error
tjxj
commited on
Commit
·
5aac920
1
Parent(s):
f49e74b
1.0
Browse files- .history/app_20220620164132.py +47 -0
- .history/packages_20220620164026.txt +0 -0
- .history/packages_20220620164115.txt +2 -0
- .history/packages_20220620164119.txt +2 -0
- app.py +1 -5
- packages.txt +2 -0
.history/app_20220620164132.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
45 |
+
|
46 |
+
|
47 |
+
|
.history/packages_20220620164026.txt
ADDED
File without changes
|
.history/packages_20220620164115.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ghostscript
|
2 |
+
python3-tk
|
.history/packages_20220620164119.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ghostscript
|
2 |
+
python3-tk
|
app.py
CHANGED
@@ -1,11 +1,7 @@
|
|
1 |
#-*- coding : utf-8-*-
|
2 |
import os,subprocess,base64
|
3 |
from subprocess import STDOUT #os process manipuation
|
4 |
-
|
5 |
-
os.system("apt-get install sudo")
|
6 |
-
os.system("sudo apt update")
|
7 |
-
os.system("apt-get install -y libgl1-mesa-glx")
|
8 |
-
os.system("apt install ghostscript python3-tk")
|
9 |
|
10 |
import streamlit as st
|
11 |
# @st.cache
|
|
|
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
|
packages.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ghostscript
|
2 |
+
python3-tk
|