Doron Adler commited on
Commit
549320b
1 Parent(s): d92c123

Concat aligned input image (or input image if a face was not found) and the drag output

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,7 +1,6 @@
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("sudo apt-get -y install cmake")
5
  os.system("pip install dlib")
6
  import sys
7
  import face_detection
@@ -44,6 +43,12 @@ def align_first_face(image_in, size=256):
44
 
45
  return im_array
46
 
 
 
 
 
 
 
47
  import gradio as gr
48
 
49
  def face2drag(
@@ -55,6 +60,7 @@ def face2drag(
55
  input = torch.Tensor(aligned_img)
56
  output = net(input)
57
  output = tensor2im(output[0])
 
58
  return output
59
 
60
  import os
@@ -77,5 +83,5 @@ title = "Dragness"
77
  description = "Gradio demo for Drag finetuned Pixel2Style2Pixel. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
78
  article = "<p style='text-align: center'><a href='https://github.com/justinpinkney/pixel2style2pixel/tree/nw' target='_blank'>Github Repo</a></p><p style='text-align: center'>samples: <img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00001.jpg' alt='Sample00001'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00002.jpg' alt='Sample00002'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00003.jpg' alt='Sample00003'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00004.jpg' alt='Sample00004'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00005.jpg' alt='Sample00005'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00006.jpg' alt='Sample00006'/></p><p>Drag model was fine tuned by Doron Adler</p>"
79
 
80
- examples=[['Example00001.jpg'],['Example00002.jpg'],['Fiona-Example00003.jpg'],['Example00004.jpg'],['Example00005.jpg'],['Example00006.jpg'],['Example00007.jpg']]
81
  gr.Interface(inference, gr.inputs.Image(type="pil",shape=(256,256)), gr.outputs.Image(type="pil"),title=title,description=description,article=article,examples=examples,enable_queue=True).launch()
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
43
 
44
  return im_array
45
 
46
+ def img_concat_h(im1, im2):
47
+ dst = Image.new('RGB', (im1.width + im2.width, im1.height))
48
+ dst.paste(im1, (0, 0))
49
+ dst.paste(im2, (im1.width, 0))
50
+ return dst
51
+
52
  import gradio as gr
53
 
54
  def face2drag(
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
83
  description = "Gradio demo for Drag finetuned Pixel2Style2Pixel. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
84
  article = "<p style='text-align: center'><a href='https://github.com/justinpinkney/pixel2style2pixel/tree/nw' target='_blank'>Github Repo</a></p><p style='text-align: center'>samples: <img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00001.jpg' alt='Sample00001'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00002.jpg' alt='Sample00002'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00003.jpg' alt='Sample00003'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00004.jpg' alt='Sample00004'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00005.jpg' alt='Sample00005'/><img src='https://hf.space/gradioiframe/Norod78/Dragness/file/Sample00006.jpg' alt='Sample00006'/></p><p>Drag model was fine tuned by Doron Adler</p>"
85
 
86
+ examples=[['Example00001.jpg'],['Example00002.jpg'],['Example00003.jpg'],['Example00004.jpg'],['Example00005.jpg'],['Example00006.jpg'],['Example00007.jpg']]
87
  gr.Interface(inference, gr.inputs.Image(type="pil",shape=(256,256)), gr.outputs.Image(type="pil"),title=title,description=description,article=article,examples=examples,enable_queue=True).launch()