File size: 1,811 Bytes
488eece
b506075
488eece
b506075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6df9b7
b506075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import os
def run_talkshow_model(audio_file):
    # Path to the TalkSHOW demo script
    demo_script = 'scripts/demo.py'
    
    # Configuration and model parameters
    config_file = './config/LS3DCG.json'
    body_model_name = 's2g_LS3DCG'
    body_model_path = 'experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth'
    
    # Path of the uploaded audio file
    audio_file_path = audio_file
    
    # Path where the output .mp4 video will be saved
    output_video_path = './output_video/result.mp4'
    
    # Run the demo.py script with the necessary arguments
    command = [
        'python', demo_script,
        '--config_file', config_file,
        '--infer',
        '--audio_file', audio_file_path,
        '--body_model_name', body_model_name,
        '--body_model_path', body_model_path,
        '--id', '0',
        '--output', output_video_path  # Assuming demo.py has an argument to specify output
    ]
    
    try:
        # Run the subprocess and capture output
        subprocess.run(command, check=True, capture_output=True, text=True)
        
        # Check if the .mp4 file is generated
        if os.path.exists(output_video_path):
            return output_video_path  # Return the path of the generated video
        else:
            return "Error: Output video not generated."
    
    except subprocess.CalledProcessError as e:
        return f"Error running the model: {e.stderr}"  # Return the error message

# Set up the Gradio interface
interface = gr.Interface(
    fn=run_talkshow_model, 
    inputs=gr.Audio(source="upload", type="filepath"), 
    outputs=gr.Video(),  # Use gr.Video to output the generated .mp4 video
    title="TalkSHOW: Audio to Mesh"
)

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