Ii commited on
Commit
3179518
·
verified ·
1 Parent(s): d4991cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -41,14 +41,13 @@ refacer = Refacer(force_cpu=args.force_cpu, colab_performance=args.colab_perform
41
  num_faces = args.max_num_faces
42
 
43
  # Run function for refacing video
44
- def run(*vars):
45
- video_path = vars[0]
46
- origins = vars[1:(num_faces+1)]
47
- destinations = vars[(num_faces+1):(num_faces*2)+1]
48
- thresholds = vars[(num_faces*2)+1:]
49
 
50
  faces = []
51
- for k in range(0, num_faces):
52
  if origins[k] is not None and destinations[k] is not None:
53
  faces.append({
54
  'origin': origins[k],
@@ -60,7 +59,7 @@ def run(*vars):
60
  refaced_video_path = refacer.reface(video_path, faces) # refaced video path
61
  print(f"Refaced video can be found at {refaced_video_path}")
62
 
63
- return refaced_video_path # Return the file path to show in Gradio output
64
 
65
  # Prepare Gradio components
66
  origin = []
@@ -69,12 +68,12 @@ thresholds = []
69
 
70
  with gr.Blocks() as demo:
71
  with gr.Row():
72
- gr.Markdown("# Refacer")
73
  with gr.Row():
74
- video = gr.Video(label="Original video", format="mp4")
75
- video2 = gr.Video(label="Refaced video", interactive=False, format="mp4")
76
 
77
- for i in range(0, num_faces):
78
  with gr.Tab(f"Face #{i+1}"):
79
  with gr.Row():
80
  origin.append(gr.Image(label="Face to replace"))
@@ -85,6 +84,7 @@ with gr.Blocks() as demo:
85
  with gr.Row():
86
  button = gr.Button("Reface", variant="primary")
87
 
 
88
  button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
89
 
90
  # Launch the Gradio app
 
41
  num_faces = args.max_num_faces
42
 
43
  # Run function for refacing video
44
+ def run(video_path, *vars):
45
+ origins = vars[:num_faces]
46
+ destinations = vars[num_faces:2*num_faces]
47
+ thresholds = vars[2*num_faces:]
 
48
 
49
  faces = []
50
+ for k in range(num_faces):
51
  if origins[k] is not None and destinations[k] is not None:
52
  faces.append({
53
  'origin': origins[k],
 
59
  refaced_video_path = refacer.reface(video_path, faces) # refaced video path
60
  print(f"Refaced video can be found at {refaced_video_path}")
61
 
62
+ return refaced_video_path # Directly return the refaced video path
63
 
64
  # Prepare Gradio components
65
  origin = []
 
68
 
69
  with gr.Blocks() as demo:
70
  with gr.Row():
71
+ gr.Markdown("# Refacer - Replace Faces in Video")
72
  with gr.Row():
73
+ video = gr.Video(label="Original Video", format="mp4")
74
+ video2 = gr.Video(label="Refaced Video", format="mp4", interactive=False)
75
 
76
+ for i in range(num_faces):
77
  with gr.Tab(f"Face #{i+1}"):
78
  with gr.Row():
79
  origin.append(gr.Image(label="Face to replace"))
 
84
  with gr.Row():
85
  button = gr.Button("Reface", variant="primary")
86
 
87
+ # Updated: Directly display the refaced video in the output
88
  button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
89
 
90
  # Launch the Gradio app