Spaces:
Sleeping
Sleeping
Ajout de clean
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import openpyxl
|
|
9 |
from openpyxl.utils.dataframe import dataframe_to_rows
|
10 |
from openpyxl.styles import numbers
|
11 |
from openpyxl.worksheet.table import Table, TableStyleInfo
|
12 |
-
|
13 |
|
14 |
def extract_pages(pdf_path, start_page, end_page, output_path):
|
15 |
reader = PdfReader(pdf_path)
|
@@ -228,6 +228,20 @@ def ui(input_files):
|
|
228 |
|
229 |
return output_zip
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
with gr.Blocks() as appli:
|
232 |
gr.Markdown("## CBCR PDF to Excel Conversion Tool")
|
233 |
input_files = gr.File(label="Select an input folder", file_count="directory")
|
@@ -236,5 +250,6 @@ with gr.Blocks() as appli:
|
|
236 |
|
237 |
process_button.click(fn=ui, inputs=input_files, outputs=download_link)
|
238 |
|
|
|
239 |
appli.launch()
|
240 |
|
|
|
9 |
from openpyxl.utils.dataframe import dataframe_to_rows
|
10 |
from openpyxl.styles import numbers
|
11 |
from openpyxl.worksheet.table import Table, TableStyleInfo
|
12 |
+
import tempfile
|
13 |
|
14 |
def extract_pages(pdf_path, start_page, end_page, output_path):
|
15 |
reader = PdfReader(pdf_path)
|
|
|
228 |
|
229 |
return output_zip
|
230 |
|
231 |
+
|
232 |
+
def clear_gradio_temp():
|
233 |
+
temp_dir = tempfile.gettempdir() # Get system temp directory
|
234 |
+
for folder in os.listdir(temp_dir):
|
235 |
+
folder_path = os.path.join(temp_dir, folder)
|
236 |
+
if "gradio" in folder_path.lower(): # Identify Gradio temp folders
|
237 |
+
try:
|
238 |
+
shutil.rmtree(folder_path) # Remove folder and contents
|
239 |
+
print(f"Deleted: {folder_path}")
|
240 |
+
except Exception as e:
|
241 |
+
print(f"Failed to delete {folder_path}: {e}")
|
242 |
+
|
243 |
+
|
244 |
+
|
245 |
with gr.Blocks() as appli:
|
246 |
gr.Markdown("## CBCR PDF to Excel Conversion Tool")
|
247 |
input_files = gr.File(label="Select an input folder", file_count="directory")
|
|
|
250 |
|
251 |
process_button.click(fn=ui, inputs=input_files, outputs=download_link)
|
252 |
|
253 |
+
clear_gradio_temp()
|
254 |
appli.launch()
|
255 |
|