File size: 1,807 Bytes
d26f817
 
 
fb98dac
 
 
 
 
 
 
a40e0c1
d26f817
fb98dac
7227d67
fb98dac
 
 
 
 
d26f817
 
 
fb98dac
d26f817
 
 
 
7227d67
d26f817
 
 
 
 
 
 
 
fb98dac
 
7227d67
 
 
 
 
 
 
195b61e
d26f817
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json

def get_log_name(config_file):
    """Load the JSON configuration file to extract the log name."""
    with open(config_file, 'r') as f:
        config = json.load(f)
    return config['Log']['name']  # Adjust this if the structure is different

def run_inference(audio_file):
    # Extract the audio filename
    audio_filename = os.path.basename(audio_file)

    # Load the configuration to get the log name
    config_file = './config/LS3DCG.json'
    config_log_name = get_log_name(config_file)

    # Define the command to run your script
    command = [
        "python", "scripts/demo.py",
        "--config_file", config_file,
        "--infer",
        "--audio_file", audio_file,
        "--body_model_name", "s2g_LS3DCG",
        "--body_model_path", "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth",
        "--id", "0"
    ]
    
    # Run the command and capture the output
    result = subprocess.run(command, capture_output=True, text=True)
    
    # Check for errors
    if result.returncode != 0:
        return f"Error: {result.stderr}"

    # Construct the output video filename based on the log name
    output_video_path = f'visualise/video/{config_log_name}/{audio_filename.rsplit(".", 1)[0]}.mp4'
    
    # Check if the video file exists and return the path
    if os.path.exists(output_video_path):
        return output_video_path
    else:
        return "Video file not found."

# Create Gradio interface
interface = gr.Interface(
    fn=run_inference,
    inputs=gr.Audio(source="upload", type="filepath"),
    outputs=gr.Video(type="file"),
    title="Audio to Video Inference",
    description="Upload an audio file to generate a video."
)

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