dunlp commited on
Commit
2d118fc
1 Parent(s): 92023a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
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 an in-memory ZIP file for the output
39
- output_zip_buffer = io.BytesIO()
40
- with zipfile.ZipFile(output_zip_buffer, 'w') as zf:
 
 
 
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
- # Finalize the output
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 expects bytes or path
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",