NihalGazi commited on
Commit
f4561d2
·
verified ·
1 Parent(s): 53352ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -21,6 +21,7 @@ except (ImportError, AttributeError):
21
  face_mesh = None
22
 
23
  # --- Helper Functions ---
 
24
  def get_landmarks(img, landmark_step=1):
25
  if img is None or face_mesh is None:
26
  return None
@@ -40,6 +41,7 @@ def get_landmarks(img, landmark_step=1):
40
  corners = np.array([[0,0],[w-1,0],[0,h-1],[w-1,h-1]], dtype=np.float32)
41
  return np.vstack((landmarks, corners))
42
 
 
43
  def calculate_delaunay_triangles(rect, points):
44
  if points is None or len(points)<3:
45
  return []
@@ -65,6 +67,7 @@ def calculate_delaunay_triangles(rect, points):
65
  delaunay.append(idxs)
66
  return delaunay
67
 
 
68
  def warp_triangle(img1,img2,t1,t2):
69
  if len(t1)!=3 or len(t2)!=3:
70
  return
@@ -82,6 +85,7 @@ def warp_triangle(img1,img2,t1,t2):
82
  y1,y2=r2[1],r2[1]+r2[3]; x1,x2=r2[0],r2[0]+r2[2]
83
  img2[y1:y2,x1:x2]=img2[y1:y2,x1:x2]*(1-mask)+warped
84
 
 
85
  def morph_faces(img1, img2, alpha, dim, step):
86
  if img1 is None or img2 is None:
87
  return np.zeros((dim,dim,3),dtype=np.uint8)
@@ -100,6 +104,7 @@ def morph_faces(img1, img2, alpha, dim, step):
100
  out=(1-alpha)*Wa+alpha*Wb
101
  return (out*255).astype(np.uint8)
102
 
 
103
  def process_video(video_path, target_img, trans, res, step, progress=gr.Progress()):
104
  if video_path is None or target_img is None:
105
  tmp=tempfile.NamedTemporaryFile(delete=False,suffix='.mp4').name
@@ -141,7 +146,9 @@ with gr.Blocks(css=css) as iface:
141
  fn=process_video,
142
  inputs=[vid,img,trans,res,step],
143
  outputs=out,
144
- progress=prog
145
  )
146
  gr.Markdown("---\n*Built with Gradio, OpenCV & MediaPipe.*")
147
- if __name__=='__main__': iface.launch(debug=True)
 
 
 
21
  face_mesh = None
22
 
23
  # --- Helper Functions ---
24
+
25
  def get_landmarks(img, landmark_step=1):
26
  if img is None or face_mesh is None:
27
  return None
 
41
  corners = np.array([[0,0],[w-1,0],[0,h-1],[w-1,h-1]], dtype=np.float32)
42
  return np.vstack((landmarks, corners))
43
 
44
+
45
  def calculate_delaunay_triangles(rect, points):
46
  if points is None or len(points)<3:
47
  return []
 
67
  delaunay.append(idxs)
68
  return delaunay
69
 
70
+
71
  def warp_triangle(img1,img2,t1,t2):
72
  if len(t1)!=3 or len(t2)!=3:
73
  return
 
85
  y1,y2=r2[1],r2[1]+r2[3]; x1,x2=r2[0],r2[0]+r2[2]
86
  img2[y1:y2,x1:x2]=img2[y1:y2,x1:x2]*(1-mask)+warped
87
 
88
+
89
  def morph_faces(img1, img2, alpha, dim, step):
90
  if img1 is None or img2 is None:
91
  return np.zeros((dim,dim,3),dtype=np.uint8)
 
104
  out=(1-alpha)*Wa+alpha*Wb
105
  return (out*255).astype(np.uint8)
106
 
107
+
108
  def process_video(video_path, target_img, trans, res, step, progress=gr.Progress()):
109
  if video_path is None or target_img is None:
110
  tmp=tempfile.NamedTemporaryFile(delete=False,suffix='.mp4').name
 
146
  fn=process_video,
147
  inputs=[vid,img,trans,res,step],
148
  outputs=out,
149
+ show_progress=True
150
  )
151
  gr.Markdown("---\n*Built with Gradio, OpenCV & MediaPipe.*")
152
+
153
+ if __name__=='__main__':
154
+ iface.launch(debug=True)