File size: 1,452 Bytes
1b8d40c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
from pydub import AudioSegment

# Path to the TalkShow demo script and configuration
DEMO_SCRIPT_PATH = "scripts/demo.py"
CONFIG_FILE = "./config/LS3DCG.json"
BODY_MODEL_PATH = "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth"
OUTPUT_MP4_PATH = "./output/demo_output.mp4"
STYLE_WAV_PATH = "./demo_audio/style.wav"

def convert_audio_to_wav(input_audio):
    # Convert the input audio to .wav format
    audio = AudioSegment.from_file(input_audio)
    audio.export(STYLE_WAV_PATH, format="wav")
    return STYLE_WAV_PATH

def run_demo_and_get_video(input_audio):
    # Convert the input audio to .wav
    wav_path = convert_audio_to_wav(input_audio)

    # Run the demo script with the specified arguments
    command = [
        "python", DEMO_SCRIPT_PATH,
        "--config_file", CONFIG_FILE,
        "--infer",
        "--audio_file", wav_path,
        "--body_model_name", "s2g_LS3DCG",
        "--body_model_path", BODY_MODEL_PATH,
        "--id", "0"
    ]
    subprocess.run(command, check=True)

    # Check if the output file exists
    if os.path.exists(OUTPUT_MP4_PATH):
        return OUTPUT_MP4_PATH
    else:
        return "Error: Output video not generated."

# Define the Gradio interface
interface = gr.Interface(
    fn=run_demo_and_get_video,
    inputs=gr.Audio(source="upload", type="filepath"),
    outputs=gr.Video()
)

# Launch the app
if __name__ == "__main__":
    interface.launch()