Doron Adler commited on
Commit
08617c1
1 Parent(s): dde6ed2

Also Exif transpose images without detected faces

Browse files

Files changed (2) hide show
  1. .gitignore +2 -0
  2. app.py +13 -6
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
1
+ *.pyc
2
+ gradio_queue.db
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
- #os.system("gdown https://drive.google.com/uc?id=1WEST2O6svlQWpJNomX3947Q2bfJz4bAJ")
3
- #os.system("gdown https://drive.google.com/uc?id=1CbnhlUI9Tms2o7S2eCg9qwGXZFCyROYy")
4
  os.system("pip install dlib")
5
  import sys
6
  import face_detection
@@ -36,6 +35,10 @@ def find_aligned_face(image_in, size=256):
36
  def align_first_face(image_in, size=256):
37
  aligned_image, n_faces, quad = find_aligned_face(image_in,size=size)
38
  if n_faces == 0:
 
 
 
 
39
  image_in = image_in.resize((size, size))
40
  im_array = image_as_array(image_in)
41
  else:
@@ -57,10 +60,14 @@ def face2drag(
57
  ) -> Image.Image:
58
 
59
  aligned_img = align_first_face(img)
60
- input = torch.Tensor(aligned_img)
61
- output = net(input)
62
- output = tensor2im(output[0])
63
- output = img_concat_h(tensor2im(torch.Tensor(aligned_img)[0]), output)
 
 
 
 
64
  return output
65
 
66
  import os
1
  import os
2
+ os.system("pip install --upgrade pip")
 
3
  os.system("pip install dlib")
4
  import sys
5
  import face_detection
35
  def align_first_face(image_in, size=256):
36
  aligned_image, n_faces, quad = find_aligned_face(image_in,size=size)
37
  if n_faces == 0:
38
+ try:
39
+ image_in = ImageOps.exif_transpose(image_in)
40
+ except:
41
+ print("exif problem, not rotating")
42
  image_in = image_in.resize((size, size))
43
  im_array = image_as_array(image_in)
44
  else:
60
  ) -> Image.Image:
61
 
62
  aligned_img = align_first_face(img)
63
+ if aligned_img is None:
64
+ output=None
65
+ else:
66
+ input = torch.Tensor(aligned_img)
67
+ output = net(input)
68
+ output = tensor2im(output[0])
69
+ output = img_concat_h(tensor2im(torch.Tensor(aligned_img)[0]), output)
70
+
71
  return output
72
 
73
  import os