Aymeric Ducatez commited on
Commit
04af2e2
·
1 Parent(s): 178e188
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -35,7 +35,7 @@ def reduce_pdf(pdf_list,reduced_pdf_folder):
35
  end_page = int(match.group(2))
36
  base_name = re.sub(r'_\d+-\d+\.pdf$', '.pdf', filename)
37
 
38
- pdf_path = os.path.join(pdf_folder, filename)
39
  output_path = os.path.join(reduced_pdf_folder, base_name)
40
 
41
  extract_pages(pdf_path, start_page, end_page, output_path)
@@ -202,17 +202,30 @@ def reduce_and_convert(input_folder):
202
  convert_to_excel(reduced_pdf_folder, output_folder)
203
 
204
 
205
- def ui(input_folder):
206
- zip_path = reduce_and_convert(input_folder)
207
- zip_path = "./output.zip"
208
- return zip_path
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  with gr.Blocks() as appli:
211
  gr.Markdown("## PDF Reduction & Conversion Tool")
212
- input_folder = gr.File(label="Select an input folder", file_count="directory")
213
  process_button = gr.Button("Process Files")
214
  download_link = gr.File(label="Download Processed Zip")
215
 
216
- process_button.click(fn=ui, inputs=input_folder, outputs=download_link)
217
 
218
  appli.launch()
 
35
  end_page = int(match.group(2))
36
  base_name = re.sub(r'_\d+-\d+\.pdf$', '.pdf', filename)
37
 
38
+ pdf_path = filename
39
  output_path = os.path.join(reduced_pdf_folder, base_name)
40
 
41
  extract_pages(pdf_path, start_page, end_page, output_path)
 
202
  convert_to_excel(reduced_pdf_folder, output_folder)
203
 
204
 
205
+ def ui(input_files):
206
+ output_zip = "./output.zip"
207
+ if os.path.exists(output_zip):
208
+ os.remove(output_zip)
209
+
210
+ extract_folder = "./input_folder"
211
+ if os.path.exists(extract_folder):
212
+ shutil.rmtree(extract_folder)
213
+ os.makedirs(extract_folder)
214
+
215
+ # Move files into the extract_folder
216
+ for file_path in input_files:
217
+ shutil.copy(file_path, extract_folder)
218
+
219
+ reduce_and_convert(extract_folder)
220
+
221
+ return output_zip
222
 
223
  with gr.Blocks() as appli:
224
  gr.Markdown("## PDF Reduction & Conversion Tool")
225
+ input_files = gr.File(label="Select an input folder", file_count="directory")
226
  process_button = gr.Button("Process Files")
227
  download_link = gr.File(label="Download Processed Zip")
228
 
229
+ process_button.click(fn=ui, inputs=input_files, outputs=download_link)
230
 
231
  appli.launch()