Ii
commited on
Update app.py
Browse files
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 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
thresholds = vars[(num_faces*2)+1:]
|
| 49 |
|
| 50 |
faces = []
|
| 51 |
-
for k in range(
|
| 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 #
|
| 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
|
| 75 |
-
video2 = gr.Video(label="Refaced
|
| 76 |
|
| 77 |
-
for i in range(
|
| 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
|