Charbel Malo commited on
Commit
be02ec2
·
verified ·
1 Parent(s): 8cb8695

Update face_enhancer.py

Browse files
Files changed (1) hide show
  1. face_enhancer.py +5 -0
face_enhancer.py CHANGED
@@ -5,17 +5,21 @@ import gfpgan
5
  from PIL import Image
6
  from upscaler.RealESRGAN import RealESRGAN
7
  from upscaler.codeformer import CodeFormerEnhancer
 
8
 
 
9
  def gfpgan_runner(img, model):
10
  _, imgs, _ = model.enhance(img, paste_back=True, has_aligned=True)
11
  return imgs[0]
12
 
13
 
 
14
  def realesrgan_runner(img, model):
15
  img = model.predict(img)
16
  return img
17
 
18
 
 
19
  def codeformer_runner(img, model):
20
  img = model.enhance(img)
21
  return img
@@ -40,6 +44,7 @@ def get_available_enhancer_names():
40
  return available
41
 
42
 
 
43
  def load_face_enhancer_model(name='GFPGAN', device='cuda' if torch.cuda.is_available() else 'cpu'):
44
  assert name in get_available_enhancer_names() + cv2_interpolations, f"Face enhancer {name} unavailable."
45
  if name in supported_enhancers.keys():
 
5
  from PIL import Image
6
  from upscaler.RealESRGAN import RealESRGAN
7
  from upscaler.codeformer import CodeFormerEnhancer
8
+ import spaces
9
 
10
+ @spaces.GPU(enable_queue=True)
11
  def gfpgan_runner(img, model):
12
  _, imgs, _ = model.enhance(img, paste_back=True, has_aligned=True)
13
  return imgs[0]
14
 
15
 
16
+ @spaces.GPU(enable_queue=True)
17
  def realesrgan_runner(img, model):
18
  img = model.predict(img)
19
  return img
20
 
21
 
22
+ @spaces.GPU(enable_queue=True)
23
  def codeformer_runner(img, model):
24
  img = model.enhance(img)
25
  return img
 
44
  return available
45
 
46
 
47
+ @spaces.GPU(enable_queue=True)
48
  def load_face_enhancer_model(name='GFPGAN', device='cuda' if torch.cuda.is_available() else 'cpu'):
49
  assert name in get_available_enhancer_names() + cv2_interpolations, f"Face enhancer {name} unavailable."
50
  if name in supported_enhancers.keys():