-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_funcs.py
43 lines (34 loc) · 1.29 KB
/
app_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import zlib
import shutil
import zipfile
import streamlit as st
import subprocess as sp
zip_path = "compressed/"
@st.cache(persist=True,allow_output_mutation=False,show_spinner=True,suppress_st_warning=True)
def clean_directory(dir):
shutil.rmtree(dir)
os.makedirs(dir)
@st.cache(persist=True,allow_output_mutation=False,show_spinner=True,suppress_st_warning=True)
def get_all_file_paths(directory):
file_paths = []
for root, directories, files in os.walk(directory):
for filename in files:
filepath = os.path.join(root, filename)
file_paths.append(filepath)
return file_paths
@st.cache(persist=True,allow_output_mutation=True,show_spinner=False,suppress_st_warning=True)
def compress():
directory = './output'
file_paths = get_all_file_paths(directory)
print('Following files will be zipped:')
for file_name in file_paths:
print(file_name)
with zipfile.ZipFile(zip_path + 'OCR_PDFs.zip','w') as zip:
for file in file_paths:
zip.write(file)
print('All files zipped successfully!')
@st.cache(persist=True,allow_output_mutation=True,show_spinner=False,suppress_st_warning=True)
def download_success():
st.balloons()
st.success('✅ Download Successful !!')