File size: 1,777 Bytes
1cd3497
 
2768572
79883d7
2768572
 
 
 
 
 
537ba12
2768572
79883d7
1cd3497
 
 
ab7ed04
1cd3497
 
 
 
 
 
ab7ed04
30dd27d
 
ab7ed04
30dd27d
 
1cd3497
 
 
 
 
79883d7
2768572
 
 
 
 
 
1cd3497
 
 
 
 
06a5b99
ab7ed04
9b98523
1cd3497
8ea3b63
1cd3497
 
 
ab7ed04
1cd3497
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio as gr
import subprocess
from moviepy.editor import VideoFileClip

def convert_to_mp4_with_aac(input_path, output_path):
    # Load the video
    video = VideoFileClip(input_path)
    
    # Set the output format to mp4 with AAC codec
    video.write_videofile(output_path, codec="libx264", audio_codec="aac")

    return output_path

def execute_command(command: str) -> None:
    subprocess.run(command, check=True)

def infer(audio_input, image_path):

    output_name = "acknowledgement_english@M030_front_neutral_level1_001@male_face"

    command = [
        f"python",
        f"inference_for_demo_video.py",
        f"--wav_path={audio_input}",
        f"--style_clip_path=data/style_clip/3DMM/M030_front_neutral_level1_001.mat",
        f"--pose_path=data/pose/RichardShelby_front_neutral_level1_001.mat",
        f"--image_path={image_path}",
        f"--cfg_scale=1.0",
        f"--max_gen_len=30",
        f"--output_name={output_name}"
    ]

    execute_command(command)

    # Convert video to compatible codecs
    input_file = f"output_video/{output_name}.mp4"
    output_file = f"{output_name}.mp4"
    
    result = convert_to_mp4_with_aac(input_file, output_file)
    
    return result

with gr.Blocks() as demo:
    with gr.Column():
        with gr.Row():
            with gr.Column():
                image_path = gr.Image(label="Image", type="filepath", sources=["upload"])
                audio_input = gr.Audio(label="Audio input", type="filepath", sources=["upload"])
                run_btn = gr.Button("Run")
            with gr.Column():
                output_video = gr.Video(format="mp4")
    
    run_btn.click(
        fn = infer,
        inputs = [audio_input, image_path],
        outputs = [output_video]
    )

demo.launch()