Spaces:
Running
Running
File size: 1,555 Bytes
4f68924 d486c38 25e496d 351a77b 716c402 351a77b 716c402 351a77b 716c402 351a77b 04af2e2 716c402 04af2e2 0e91585 04af2e2 fdf393b 0e91585 04af2e2 0e91585 04af2e2 4f68924 d486c38 4f68924 720a5cf 04af2e2 4f68924 2c5fdb6 4f68924 04af2e2 4f68924 2c5fdb6 |
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 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import os
import shutil
import tempfile
from reduce_and_convert_PDF import reduce_and_convert
def clear_gradio_temp(exclude_files):
temp_dir = tempfile.gettempdir()
for folder in os.listdir(temp_dir):
folder_path = os.path.join(temp_dir, folder)
if "gradio" in folder_path.lower():
should_skip = any(file_path.startswith(folder_path) for file_path in exclude_files)
if should_skip:
continue
try:
shutil.rmtree(folder_path)
print(f"Deleted: {folder_path}")
except Exception as e:
print(f"Failed to delete {folder_path}: {e}")
def ui(input_files):
clear_gradio_temp(input_files)
output_zip = "./output.zip"
if os.path.exists(output_zip):
os.remove(output_zip)
input_folder = "./input_folder"
if os.path.exists(input_folder):
shutil.rmtree(input_folder)
os.makedirs(input_folder)
# Move files into the extract_folder
for file_path in input_files:
print(file_path)
shutil.copy(file_path, input_folder)
reduce_and_convert(input_folder)
return output_zip
with gr.Blocks() as appli:
gr.Markdown("## CBCR PDF to Excel Conversion Tool")
input_files = gr.File(label="Select an input folder", file_count="directory")
process_button = gr.Button("Process Files")
download_link = gr.File(label="Processed Zip")
process_button.click(fn=ui, inputs=input_files, outputs=download_link)
appli.launch()
|