Ahsen Khaliq commited on
Commit
12f4e43
1 Parent(s): 3ed1d00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -4,11 +4,26 @@ from PIL import Image
4
 
5
  os.system("wget https://www.dropbox.com/s/fgupbov77x4rrru/blendgan.pt")
6
  os.system("wget https://www.dropbox.com/s/v8q0dd3r4u20659/psp_encoder.pt")
 
 
 
 
 
 
 
 
 
7
 
8
  def inference(content, style, index):
9
  content.save('content.png')
10
  style.save('style.png')
11
- os.system("""python style_transfer_folder.py --size 1024 --add_weight_index """+str(int(index))+""" --ckpt ./blendgan.pt --psp_encoder_ckpt ./psp_encoder.pt --style_img_path style.png --input_img_path content.png""")
 
 
 
 
 
 
12
  return "out.jpg"
13
 
14
  title = "BlendGAN"
4
 
5
  os.system("wget https://www.dropbox.com/s/fgupbov77x4rrru/blendgan.pt")
6
  os.system("wget https://www.dropbox.com/s/v8q0dd3r4u20659/psp_encoder.pt")
7
+ os.system("wget https://github.com/kim-ninh/align_face_ffhq/raw/main/shape_predictor_68_face_landmarks.dat")
8
+
9
+ from ffhq_dataset.gen_aligned_image import FaceAlign
10
+
11
+
12
+ fa = FaceAlign()
13
+ import cv2
14
+
15
+
16
 
17
  def inference(content, style, index):
18
  content.save('content.png')
19
  style.save('style.png')
20
+ imgc = cv2.imread('content.png')
21
+ img_cropc = fa.get_crop_image(imgc)
22
+ cv2.imwrite('contentcrop.png', img_cropc)
23
+ imgs = cv2.imread('style.png')
24
+ img_crops = fa.get_crop_image(imgs)
25
+ cv2.imwrite('stylecrop.png', img_crops)
26
+ os.system("""python style_transfer_folder.py --size 1024 --add_weight_index """+str(int(index))+""" --ckpt ./blendgan.pt --psp_encoder_ckpt ./psp_encoder.pt --style_img_path stylecrop.png --input_img_path contentcrop.png""")
27
  return "out.jpg"
28
 
29
  title = "BlendGAN"