gschleusner commited on
Commit
961d741
·
1 Parent(s): cc84872

Back to temp PDf storage

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -2,7 +2,9 @@ import fitz # PyMuPDF
2
  import gradio as gr
3
  import zipfile
4
  import io
 
5
  from datetime import datetime
 
6
 
7
  # Helper function to find color areas
8
  def find_color_areas(page, target_color, tolerance=30):
@@ -139,12 +141,15 @@ def process_pdf_files(input_pdfs, selected_color_comment_indices, tolerance, cus
139
  # Move pointer to the beginning of the ZIP file BytesIO object
140
  zip_in_memory.seek(0)
141
 
142
- # Set the filename for the ZIP file
143
  current_date = datetime.now().strftime("%Y-%m-%d")
144
- zip_filename = f"CoordinationPDFS_{current_date}.zip"
 
 
 
 
145
 
146
- # Return the in-memory ZIP file and its filename for Gradio to download
147
- return (zip_filename, zip_in_memory)
148
 
149
  # Define the Gradio interface
150
  interface = gr.Interface(
 
2
  import gradio as gr
3
  import zipfile
4
  import io
5
+ import os
6
  from datetime import datetime
7
+ import tempfile
8
 
9
  # Helper function to find color areas
10
  def find_color_areas(page, target_color, tolerance=30):
 
141
  # Move pointer to the beginning of the ZIP file BytesIO object
142
  zip_in_memory.seek(0)
143
 
144
+ # Generate the current date string
145
  current_date = datetime.now().strftime("%Y-%m-%d")
146
+
147
+ # Create a named temporary file to store the ZIP
148
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=f"_CoordinationPDFS_{current_date}.zip")
149
+ with open(temp_file.name, 'wb') as tmp_file:
150
+ tmp_file.write(zip_in_memory.read())
151
 
152
+ return temp_file.name # Return the path to the temp file for Gradio to handle the download
 
153
 
154
  # Define the Gradio interface
155
  interface = gr.Interface(