jiuface commited on
Commit
07a147a
·
1 Parent(s): d8868ab

clear cuda cache

Browse files
__pycache__/cv_utils.cpython-310.pyc CHANGED
Binary files a/__pycache__/cv_utils.cpython-310.pyc and b/__pycache__/cv_utils.cpython-310.pyc differ
 
__pycache__/depth_estimator.cpython-310.pyc CHANGED
Binary files a/__pycache__/depth_estimator.cpython-310.pyc and b/__pycache__/depth_estimator.cpython-310.pyc differ
 
__pycache__/image_segmentor.cpython-310.pyc CHANGED
Binary files a/__pycache__/image_segmentor.cpython-310.pyc and b/__pycache__/image_segmentor.cpython-310.pyc differ
 
__pycache__/preprocessor.cpython-310.pyc CHANGED
Binary files a/__pycache__/preprocessor.cpython-310.pyc and b/__pycache__/preprocessor.cpython-310.pyc differ
 
app.py CHANGED
@@ -56,6 +56,8 @@ control_mode_ids = {
56
  "low_quality": 6, # supported
57
  }
58
 
 
 
59
 
60
 
61
  class calculateDuration:
@@ -94,11 +96,6 @@ def calculate_image_dimensions_for_flux(
94
 
95
  return new_width, new_height
96
 
97
- def is_mask_empty(image: Image.Image) -> bool:
98
- gray_img = image.convert("L")
99
- pixels = list(gray_img.getdata())
100
- return all(pixel == 0 for pixel in pixels)
101
-
102
  def process_mask(
103
  mask: Image.Image,
104
  mask_inflation: Optional[int] = None,
@@ -121,7 +118,7 @@ def process_mask(
121
 
122
  if mask_blur and mask_blur > 0:
123
  mask = mask.filter(ImageFilter.GaussianBlur(radius=mask_blur))
124
-
125
  return mask
126
 
127
  def upload_image_to_r2(image, account_id, access_key, secret_key, bucket_name):
@@ -143,6 +140,7 @@ def upload_image_to_r2(image, account_id, access_key, secret_key, bucket_name):
143
  buffer.seek(0)
144
  s3.upload_fileobj(buffer, bucket_name, image_file)
145
  print("upload finish", image_file)
 
146
  return image_file
147
 
148
 
@@ -189,7 +187,7 @@ def run_flux(
189
  max_sequence_length=256,
190
  joint_attention_kwargs={"scale": lora_scale}
191
  ).images[0]
192
-
193
  return generated_image
194
 
195
  @spaces.GPU(duration=120)
@@ -214,7 +212,7 @@ def process(
214
  bucket:str,
215
  progress=gr.Progress(track_tqdm=True)
216
  ):
217
- torch.cuda.empty_cache()
218
  result = {"status": "false", "message": ""}
219
  if not image_url:
220
  gr.Info("please enter image url for inpaiting")
@@ -290,7 +288,7 @@ def process(
290
 
291
  control_image = control_image.resize((width, height), Image.LANCZOS)
292
  control_mode_id = control_mode_ids[control_mode]
293
-
294
  try:
295
  generated_image = run_flux(
296
  image=image,
@@ -323,7 +321,7 @@ def process(
323
  else:
324
  result = {"status": "success", "message": "Image generated but not uploaded"}
325
 
326
-
327
  final_images = []
328
  final_images.append(image)
329
  final_images.append(mask)
 
56
  "low_quality": 6, # supported
57
  }
58
 
59
+ def clear_cuda_cache():
60
+ torch.cuda.empty_cache()
61
 
62
 
63
  class calculateDuration:
 
96
 
97
  return new_width, new_height
98
 
 
 
 
 
 
99
  def process_mask(
100
  mask: Image.Image,
101
  mask_inflation: Optional[int] = None,
 
118
 
119
  if mask_blur and mask_blur > 0:
120
  mask = mask.filter(ImageFilter.GaussianBlur(radius=mask_blur))
121
+ clear_cuda_cache()
122
  return mask
123
 
124
  def upload_image_to_r2(image, account_id, access_key, secret_key, bucket_name):
 
140
  buffer.seek(0)
141
  s3.upload_fileobj(buffer, bucket_name, image_file)
142
  print("upload finish", image_file)
143
+ clear_cuda_cache()
144
  return image_file
145
 
146
 
 
187
  max_sequence_length=256,
188
  joint_attention_kwargs={"scale": lora_scale}
189
  ).images[0]
190
+ clear_cuda_cache()
191
  return generated_image
192
 
193
  @spaces.GPU(duration=120)
 
212
  bucket:str,
213
  progress=gr.Progress(track_tqdm=True)
214
  ):
215
+ clear_cuda_cache()
216
  result = {"status": "false", "message": ""}
217
  if not image_url:
218
  gr.Info("please enter image url for inpaiting")
 
288
 
289
  control_image = control_image.resize((width, height), Image.LANCZOS)
290
  control_mode_id = control_mode_ids[control_mode]
291
+ clear_cuda_cache()
292
  try:
293
  generated_image = run_flux(
294
  image=image,
 
321
  else:
322
  result = {"status": "success", "message": "Image generated but not uploaded"}
323
 
324
+ clear_cuda_cache()
325
  final_images = []
326
  final_images.append(image)
327
  final_images.append(mask)