Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import zipfile
|
|
| 3 |
import io
|
| 4 |
import re
|
| 5 |
import traceback
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def process_files(phase, objecten_file_data, templates_zip_file_data):
|
| 8 |
try:
|
|
@@ -35,9 +37,12 @@ def process_files(phase, objecten_file_data, templates_zip_file_data):
|
|
| 35 |
with zipfile.ZipFile(io.BytesIO(templates_zip_data), 'r') as zip_ref:
|
| 36 |
template_files = {info.filename: zip_ref.read(info.filename) for info in zip_ref.infolist()}
|
| 37 |
|
| 38 |
-
# Create
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
for k in objs:
|
| 42 |
regPhase = ''
|
| 43 |
if k == '(i)SAT':
|
|
@@ -66,10 +71,8 @@ def process_files(phase, objecten_file_data, templates_zip_file_data):
|
|
| 66 |
|
| 67 |
file_path = folder_path + adjusted_filename
|
| 68 |
zf.writestr(file_path, file_content)
|
| 69 |
-
|
| 70 |
-
#
|
| 71 |
-
output_zip_buffer.seek(0)
|
| 72 |
-
return output_zip_buffer.getvalue(), "" # Return bytes and an empty error log on success
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
# Capture the full traceback
|
|
@@ -86,7 +89,7 @@ interface = gr.Interface(
|
|
| 86 |
gr.File(label="Upload Templates ZIP File", type='binary')
|
| 87 |
],
|
| 88 |
outputs=[
|
| 89 |
-
gr.File(label="Download ZIP File"), # This now
|
| 90 |
gr.Textbox(label="Error Log") # Textbox to display the error log
|
| 91 |
],
|
| 92 |
title="Template Folder Generator",
|
|
|
|
| 3 |
import io
|
| 4 |
import re
|
| 5 |
import traceback
|
| 6 |
+
import os
|
| 7 |
+
import tempfile
|
| 8 |
|
| 9 |
def process_files(phase, objecten_file_data, templates_zip_file_data):
|
| 10 |
try:
|
|
|
|
| 37 |
with zipfile.ZipFile(io.BytesIO(templates_zip_data), 'r') as zip_ref:
|
| 38 |
template_files = {info.filename: zip_ref.read(info.filename) for info in zip_ref.infolist()}
|
| 39 |
|
| 40 |
+
# Create a temporary file for the output ZIP
|
| 41 |
+
temp_dir = tempfile.mkdtemp()
|
| 42 |
+
output_zip_path = os.path.join(temp_dir, 'output.zip')
|
| 43 |
+
|
| 44 |
+
# Create the ZIP file
|
| 45 |
+
with zipfile.ZipFile(output_zip_path, 'w') as zf:
|
| 46 |
for k in objs:
|
| 47 |
regPhase = ''
|
| 48 |
if k == '(i)SAT':
|
|
|
|
| 71 |
|
| 72 |
file_path = folder_path + adjusted_filename
|
| 73 |
zf.writestr(file_path, file_content)
|
| 74 |
+
|
| 75 |
+
return output_zip_path, "" # Return the path of the ZIP file and an empty error log
|
|
|
|
|
|
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
# Capture the full traceback
|
|
|
|
| 89 |
gr.File(label="Upload Templates ZIP File", type='binary')
|
| 90 |
],
|
| 91 |
outputs=[
|
| 92 |
+
gr.File(label="Download ZIP File"), # This now receives a file path
|
| 93 |
gr.Textbox(label="Error Log") # Textbox to display the error log
|
| 94 |
],
|
| 95 |
title="Template Folder Generator",
|