dunlp commited on
Commit
09d275f
1 Parent(s): 184f2d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -3,10 +3,10 @@ import zipfile
3
  import io
4
  import re
5
 
6
- def process_files(phase, objecten_file, template_files):
7
  try:
8
  # Read and process the 'objecten.txt' file
9
- content = objecten_file.read().decode('utf-8')
10
  t = content.strip().split('\n\n')
11
  phases = ["iFAT", "(i)SAT"]
12
  objs = {p: [] for p in phases}
@@ -40,23 +40,27 @@ def process_files(phase, objecten_file, template_files):
40
  regPhase = r'fat'
41
 
42
  # Filter template files for this phase
43
- phase_templates = [f for f in template_files if re.search(regPhase, f.name, re.IGNORECASE)]
 
 
 
 
 
44
  if not phase_templates:
45
  error_msg = f"Phase {k} has no templates."
46
  return None, error_msg
47
 
48
  for o in objs[k]:
49
  folder_path = f"{o}/"
50
- for f in phase_templates:
51
- template_filename = f.name
52
  # Adjust filename if needed
53
  if re.search(r"hut_\d{4}[a-zA-Z]{2}", template_filename, re.IGNORECASE):
54
  adjusted_filename = template_filename[:4] + o + template_filename[10:]
55
  else:
56
  adjusted_filename = template_filename
57
 
58
- file_content = f.read()
59
- f.seek(0) # Reset file pointer
60
  file_path = folder_path + adjusted_filename
61
  zf.writestr(file_path, file_content)
62
  zip_buffer.seek(0)
@@ -70,8 +74,8 @@ interface = gr.Interface(
70
  fn=process_files,
71
  inputs=[
72
  gr.Dropdown(choices=phase_options, label="Select Phase"),
73
- gr.File(label="Upload 'objecten.txt' File", type='file'),
74
- gr.File(label="Upload Template Files", type='file', multiple=True)
75
  ],
76
  outputs=[
77
  gr.File(label="Download ZIP File"),
 
3
  import io
4
  import re
5
 
6
+ def process_files(phase, objecten_file_dict, template_files_data):
7
  try:
8
  # Read and process the 'objecten.txt' file
9
+ content = objecten_file_dict['data'].decode('utf-8')
10
  t = content.strip().split('\n\n')
11
  phases = ["iFAT", "(i)SAT"]
12
  objs = {p: [] for p in phases}
 
40
  regPhase = r'fat'
41
 
42
  # Filter template files for this phase
43
+ phase_templates = []
44
+ for file_dict in template_files_data:
45
+ filename = file_dict['name']
46
+ if re.search(regPhase, filename, re.IGNORECASE):
47
+ phase_templates.append(file_dict)
48
+
49
  if not phase_templates:
50
  error_msg = f"Phase {k} has no templates."
51
  return None, error_msg
52
 
53
  for o in objs[k]:
54
  folder_path = f"{o}/"
55
+ for file_dict in phase_templates:
56
+ template_filename = file_dict['name']
57
  # Adjust filename if needed
58
  if re.search(r"hut_\d{4}[a-zA-Z]{2}", template_filename, re.IGNORECASE):
59
  adjusted_filename = template_filename[:4] + o + template_filename[10:]
60
  else:
61
  adjusted_filename = template_filename
62
 
63
+ file_content = file_dict['data']
 
64
  file_path = folder_path + adjusted_filename
65
  zf.writestr(file_path, file_content)
66
  zip_buffer.seek(0)
 
74
  fn=process_files,
75
  inputs=[
76
  gr.Dropdown(choices=phase_options, label="Select Phase"),
77
+ gr.File(label="Upload 'objecten.txt' File", type='binary'),
78
+ gr.File(label="Upload Template Files", type='binary', multiple=True)
79
  ],
80
  outputs=[
81
  gr.File(label="Download ZIP File"),