Commit
·
506eed4
1
Parent(s):
b695510
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from subprocess import call
|
| 3 |
|
|
|
|
| 4 |
with gr.Blocks() as ui:
|
| 5 |
with gr.Row():
|
| 6 |
video = gr.File(label="Video or Image", info="Filepath of video/image that contains faces to use")
|
|
@@ -19,31 +20,35 @@ with gr.Blocks() as ui:
|
|
| 19 |
with gr.Column():
|
| 20 |
result = gr.Video()
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
]
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
[video, audio, checkpoint, pad_top, pad_bottom, pad_left, pad_right, resize_factor],
|
| 47 |
-
result)
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from subprocess import call
|
| 3 |
|
| 4 |
+
# UI Components Setup
|
| 5 |
with gr.Blocks() as ui:
|
| 6 |
with gr.Row():
|
| 7 |
video = gr.File(label="Video or Image", info="Filepath of video/image that contains faces to use")
|
|
|
|
| 20 |
with gr.Column():
|
| 21 |
result = gr.Video()
|
| 22 |
|
| 23 |
+
# Define the generate function
|
| 24 |
+
def generate(video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right):
|
| 25 |
+
if video is None or audio is None or checkpoint is None:
|
| 26 |
+
return
|
| 27 |
|
| 28 |
+
smooth = "--nosmooth" if no_smooth else ""
|
| 29 |
|
| 30 |
+
cmd = [
|
| 31 |
+
"python",
|
| 32 |
+
"inference.py",
|
| 33 |
+
"--checkpoint_path", f"checkpoints/{checkpoint}.pth",
|
| 34 |
+
"--segmentation_path", "checkpoints/face_segmentation.pth",
|
| 35 |
+
"--enhance_face", "gfpgan",
|
| 36 |
+
"--face", video.name,
|
| 37 |
+
"--audio", audio.name,
|
| 38 |
+
"--outfile", "results/output.mp4",
|
| 39 |
+
]
|
|
|
|
| 40 |
|
| 41 |
+
call(cmd)
|
| 42 |
+
return "results/output.mp4"
|
| 43 |
+
|
| 44 |
+
# Click event for the Generate button
|
| 45 |
+
generate_btn.click(
|
| 46 |
+
generate,
|
| 47 |
+
[video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right],
|
| 48 |
+
result)
|
| 49 |
|
| 50 |
+
# Create the interface
|
| 51 |
+
iface = gr.Interface(ui.queue(), "web", debug=True)
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# Launch the interface
|
| 54 |
+
iface.launch()
|