fffiloni commited on
Commit
67611b7
·
verified ·
1 Parent(s): f65cdf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -0
app.py CHANGED
@@ -93,6 +93,7 @@ def generate_image(setup_args, num_iterations):
93
  clean_dir(save_dir)
94
 
95
  try:
 
96
  steps_completed = []
97
  result_container = {"best_image": None, "total_init_rewards": None, "total_best_rewards": None}
98
 
@@ -130,11 +131,14 @@ def generate_image(setup_args, num_iterations):
130
  final_image_path = os.path.join(save_dir, "best_image.png")
131
  if os.path.exists(final_image_path):
132
  iter_images = list_iter_images(save_dir)
 
133
  yield (final_image_path, f"Final image saved at {final_image_path}", iter_images)
134
  else:
 
135
  yield (None, "Image generation completed, but no final image was found.", None)
136
 
137
  except Exception as e:
 
138
  yield (None, f"An error occurred: {str(e)}", None)
139
 
140
  def show_gallery_output(gallery_state):
 
93
  clean_dir(save_dir)
94
 
95
  try:
96
+ torch.cuda.empty_cache() # Free up cached memory
97
  steps_completed = []
98
  result_container = {"best_image": None, "total_init_rewards": None, "total_best_rewards": None}
99
 
 
131
  final_image_path = os.path.join(save_dir, "best_image.png")
132
  if os.path.exists(final_image_path):
133
  iter_images = list_iter_images(save_dir)
134
+ torch.cuda.empty_cache() # Free up cached memory
135
  yield (final_image_path, f"Final image saved at {final_image_path}", iter_images)
136
  else:
137
+ torch.cuda.empty_cache() # Free up cached memory
138
  yield (None, "Image generation completed, but no final image was found.", None)
139
 
140
  except Exception as e:
141
+ torch.cuda.empty_cache() # Free up cached memory
142
  yield (None, f"An error occurred: {str(e)}", None)
143
 
144
  def show_gallery_output(gallery_state):