Ii commited on
Commit
ac304d9
·
verified ·
1 Parent(s): 9e9cf07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -29,14 +29,13 @@ download_model()
29
  refacer = Refacer(force_cpu=False, colab_performance=False)
30
 
31
  # Run function for refacing video
32
- def run(*vars):
33
- video_path = vars[0]
34
- origins = vars[1:(num_faces+1)]
35
- destinations = vars[(num_faces+1):(num_faces*2)+1]
36
- thresholds = vars[(num_faces*2)+1:]
37
 
38
  faces = []
39
- for k in range(0, num_faces):
40
  if origins[k] is not None and destinations[k] is not None:
41
  faces.append({
42
  'origin': origins[k],
@@ -59,11 +58,6 @@ def run(*vars):
59
  return video_buffer # Gradio will handle the video display
60
 
61
  # Prepare Gradio components
62
- num_faces = 5
63
- origin = []
64
- destination = []
65
- thresholds = []
66
-
67
  with gr.Blocks() as demo:
68
  with gr.Row():
69
  gr.Markdown("# Refacer")
@@ -71,19 +65,19 @@ with gr.Blocks() as demo:
71
  video = gr.Video(label="Original video", format="mp4")
72
  video2 = gr.Video(label="Refaced video", interactive=False, format="mp4")
73
 
74
- for i in range(0, num_faces):
 
75
  with gr.Tab(f"Face #{i+1}"):
76
  with gr.Row():
77
- origin.append(gr.Image(label="Face to replace"))
78
- destination.append(gr.Image(label="Destination face"))
79
  with gr.Row():
80
  thresholds.append(gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.2))
81
 
82
  with gr.Row():
83
  button = gr.Button("Reface", variant="primary")
84
 
85
- # Click event: Refacing the video and showing the refaced video in Gradio
86
- button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
87
 
88
  # Launch the Gradio app
89
  demo.queue().launch(show_error=True, server_name="0.0.0.0", server_port=7860)
 
29
  refacer = Refacer(force_cpu=False, colab_performance=False)
30
 
31
  # Run function for refacing video
32
+ def run(video_path, *vars):
33
+ origins = vars[:5]
34
+ destinations = vars[5:10]
35
+ thresholds = vars[10:]
 
36
 
37
  faces = []
38
+ for k in range(5):
39
  if origins[k] is not None and destinations[k] is not None:
40
  faces.append({
41
  'origin': origins[k],
 
58
  return video_buffer # Gradio will handle the video display
59
 
60
  # Prepare Gradio components
 
 
 
 
 
61
  with gr.Blocks() as demo:
62
  with gr.Row():
63
  gr.Markdown("# Refacer")
 
65
  video = gr.Video(label="Original video", format="mp4")
66
  video2 = gr.Video(label="Refaced video", interactive=False, format="mp4")
67
 
68
+ origins, destinations, thresholds = [], [], []
69
+ for i in range(5):
70
  with gr.Tab(f"Face #{i+1}"):
71
  with gr.Row():
72
+ origins.append(gr.Image(label="Face to replace"))
73
+ destinations.append(gr.Image(label="Destination face"))
74
  with gr.Row():
75
  thresholds.append(gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.2))
76
 
77
  with gr.Row():
78
  button = gr.Button("Reface", variant="primary")
79
 
80
+ button.click(fn=run, inputs=[video] + origins + destinations + thresholds, outputs=[video2])
 
81
 
82
  # Launch the Gradio app
83
  demo.queue().launch(show_error=True, server_name="0.0.0.0", server_port=7860)