model2 commited on
Commit
e1d5d34
·
1 Parent(s): d81e2e0

clean up tmp dir after each run

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -197,6 +197,22 @@ def add_extra_model_paths() -> None:
197
  print("Could not find the extra_model_paths config file.")
198
 
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  add_comfyui_directory_to_sys_path()
201
  add_extra_model_paths()
202
 
@@ -262,6 +278,10 @@ def advance_blur(input_image):
262
  )
263
  outpath = f"advance-blurred-{os.urandom(16).hex()}.jpg"
264
  img.save(outpath, quality=80, dpi=(72, 72))
 
 
 
 
265
  return outpath
266
 
267
 
 
197
  print("Could not find the extra_model_paths config file.")
198
 
199
 
200
+ def clear_tmp_directory():
201
+ print("Cleaning up /tmp directory...")
202
+ image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp'}
203
+ for root, dirs, files in os.walk('/tmp'):
204
+ for file in files:
205
+ if not file.startswith('advance-blurred-'):
206
+ ext = os.path.splitext(file)[1].lower()
207
+ if ext in image_extensions:
208
+ full_path = os.path.join(root, file)
209
+ try:
210
+ os.remove(full_path)
211
+ print(f"Deleted: {full_path}")
212
+ except Exception as e:
213
+ print(f"Failed to delete {full_path}: {e}")
214
+
215
+
216
  add_comfyui_directory_to_sys_path()
217
  add_extra_model_paths()
218
 
 
278
  )
279
  outpath = f"advance-blurred-{os.urandom(16).hex()}.jpg"
280
  img.save(outpath, quality=80, dpi=(72, 72))
281
+
282
+ # Clean up the /tmp directory
283
+ clear_tmp_directory()
284
+
285
  return outpath
286
 
287