Commit ·
8ec1624
1
Parent(s): 72f3ab6
no temp output
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import zipfile
|
|
| 4 |
import io
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
# Helper function to find color areas
|
| 9 |
def find_color_areas(page, target_color, tolerance=30):
|
|
@@ -143,28 +144,12 @@ def process_pdf_files(input_pdfs, selected_color_comment_indices, tolerance, cus
|
|
| 143 |
# Generate the current date string
|
| 144 |
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 145 |
|
| 146 |
-
# Create
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
# Ensure the file is saved with the correct name
|
| 151 |
-
zip_filename = f"CoordinationPDFS_{current_date}.zip"
|
| 152 |
-
temp_filename = os.path.join(output_dir, zip_filename)
|
| 153 |
-
with open(temp_filename, 'wb') as tmp_file:
|
| 154 |
tmp_file.write(zip_in_memory.read())
|
| 155 |
-
|
| 156 |
-
# Return the
|
| 157 |
-
return f'''
|
| 158 |
-
<script>
|
| 159 |
-
var link = document.createElement('a');
|
| 160 |
-
link.href = '{temp_filename}';
|
| 161 |
-
link.download = '{zip_filename}';
|
| 162 |
-
document.body.appendChild(link);
|
| 163 |
-
link.click();
|
| 164 |
-
document.body.removeChild(link);
|
| 165 |
-
</script>
|
| 166 |
-
File is being downloaded automatically.
|
| 167 |
-
'''
|
| 168 |
|
| 169 |
# Define the Gradio interface
|
| 170 |
interface = gr.Interface(
|
|
@@ -181,7 +166,7 @@ interface = gr.Interface(
|
|
| 181 |
gr.Textbox(label="Custom Comment", placeholder="Enter custom comment for this color"),
|
| 182 |
gr.Textbox(label="Custom Stroke Color (R,G,B)", placeholder="Enter stroke color in RGB format, e.g., 0,0,255")
|
| 183 |
],
|
| 184 |
-
outputs="
|
| 185 |
title="PDF Color Region Markup"
|
| 186 |
)
|
| 187 |
|
|
|
|
| 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):
|
|
|
|
| 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(
|
|
|
|
| 166 |
gr.Textbox(label="Custom Comment", placeholder="Enter custom comment for this color"),
|
| 167 |
gr.Textbox(label="Custom Stroke Color (R,G,B)", placeholder="Enter stroke color in RGB format, e.g., 0,0,255")
|
| 168 |
],
|
| 169 |
+
outputs=gr.File(label="Download ZIP File"), # Use gr.File to trigger the download of the ZIP file
|
| 170 |
title="PDF Color Region Markup"
|
| 171 |
)
|
| 172 |
|