SohomToom commited on
Commit
ab90a8a
·
verified ·
1 Parent(s): 7d1906d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -138,16 +138,33 @@ def remove_text_dynamic_fill(img_path, output_path):
138
  image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
139
  cv2.imwrite(output_path, image)
140
 
 
 
141
  def process_folder(input_files):
142
  temp_output = tempfile.mkdtemp()
 
143
  for file in input_files:
144
  filename = os.path.basename(file.name)
145
  output_path = os.path.join(temp_output, filename)
146
  remove_text_dynamic_fill(file.name, output_path)
147
- zip_path = shutil.make_archive(temp_output, 'zip', temp_output)
 
 
 
 
 
148
  return zip_path
149
 
150
 
 
 
 
 
 
 
 
 
 
151
 
152
 
153
 
 
138
  image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
139
  cv2.imwrite(output_path, image)
140
 
141
+ import uuid
142
+
143
  def process_folder(input_files):
144
  temp_output = tempfile.mkdtemp()
145
+
146
  for file in input_files:
147
  filename = os.path.basename(file.name)
148
  output_path = os.path.join(temp_output, filename)
149
  remove_text_dynamic_fill(file.name, output_path)
150
+
151
+ unique_name = str(uuid.uuid4())[:8]
152
+ zip_path = os.path.join("/tmp", f"cleaned_output_{unique_name}.zip")
153
+ shutil.make_archive(zip_path.replace(".zip", ""), 'zip', temp_output)
154
+
155
+ delayed_cleanup(zip_path)
156
  return zip_path
157
 
158
 
159
+ import threading
160
+ import time
161
+
162
+ def delayed_cleanup(path, delay=30):
163
+ def cleanup():
164
+ time.sleep(delay)
165
+ if os.path.exists(path):
166
+ os.remove(path)
167
+ threading.Thread(target=cleanup).start()
168
 
169
 
170