AdityA36912355 commited on
Commit
bb766be
·
verified ·
1 Parent(s): a2089cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -3,6 +3,8 @@ from PIL import Image
3
  import sys
4
  import tempfile
5
  from facefusion import core
 
 
6
 
7
  def run_cli(cli_args):
8
  old_argv = sys.argv
@@ -12,13 +14,20 @@ def run_cli(cli_args):
12
  finally:
13
  sys.argv = old_argv
14
 
 
 
 
 
 
 
 
15
  def swap_faces(source_image_path, target_image_path, enhance_face=True, enhance_frame=True):
16
  provider = 'cuda'
17
 
18
  target_ext = target_image_path.split('.')[-1]
19
  output_image_file = tempfile.NamedTemporaryFile(suffix=f'.{target_ext}')
20
  output_image_path = output_image_file.name
21
-
22
  print(source_image_path)
23
  print(target_image_path)
24
  print(output_image_path)
@@ -34,7 +43,7 @@ def swap_faces(source_image_path, target_image_path, enhance_face=True, enhance_
34
  ]
35
 
36
  cli_args += [ '--frame-processors', 'face_swapper' ]
37
- cli_args += ['--trim-frame-end','2']
38
  if enhance_face:
39
  cli_args += [
40
  'face_enhancer',
@@ -67,5 +76,6 @@ demo = gr.Interface(
67
  allow_flagging="never"
68
  )
69
 
70
- if __name__ == "__main__":
71
- demo.launch(show_error=True)
 
 
3
  import sys
4
  import tempfile
5
  from facefusion import core
6
+ from moviepy.editor import VideoFileClip
7
+
8
 
9
  def run_cli(cli_args):
10
  old_argv = sys.argv
 
14
  finally:
15
  sys.argv = old_argv
16
 
17
+
18
+ def get_video_duration(video_path):
19
+ video = VideoFileClip(video_path)
20
+ duration = video.duration # duration in seconds
21
+ return duration
22
+
23
+
24
  def swap_faces(source_image_path, target_image_path, enhance_face=True, enhance_frame=True):
25
  provider = 'cuda'
26
 
27
  target_ext = target_image_path.split('.')[-1]
28
  output_image_file = tempfile.NamedTemporaryFile(suffix=f'.{target_ext}')
29
  output_image_path = output_image_file.name
30
+ duration = get_video_duration(target_image_path)
31
  print(source_image_path)
32
  print(target_image_path)
33
  print(output_image_path)
 
43
  ]
44
 
45
  cli_args += [ '--frame-processors', 'face_swapper' ]
46
+ cli_args += ['--trim-frame-end',str(duration)]
47
  if enhance_face:
48
  cli_args += [
49
  'face_enhancer',
 
76
  allow_flagging="never"
77
  )
78
 
79
+ if __name__ == "__main__":
80
+ demo.queue(api_open=True)
81
+ demo.launch(show_error=True, show_api=True)