File size: 3,740 Bytes
d414280
 
 
 
 
995b11a
d414280
 
 
995b11a
 
 
068ba96
 
995b11a
068ba96
 
 
 
 
 
995b11a
 
 
d414280
995b11a
d414280
 
995b11a
d414280
 
995b11a
 
d414280
995b11a
d414280
 
 
 
995b11a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d414280
 
 
 
 
995b11a
 
 
d414280
 
995b11a
d414280
 
995b11a
 
 
 
d414280
995b11a
 
 
 
d414280
995b11a
d414280
 
 
995b11a
 
eb5307b
995b11a
d414280
 
 
 
 
995b11a
d414280
 
 
 
995b11a
0124f58
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import gradio as gr
import os
import subprocess
import time
import traceback
import sys

def process_audio(audio_file):
    try:
        # Ensure input is a valid filepath for Gradio 3.x
        if isinstance(audio_file, dict):
            audio_file = audio_file['name']

        # Comprehensive error logging
        print(f"Processing audio file: {audio_file}")
        print(f"File exists: {os.path.exists(audio_file)}")
        print(f"Current working directory: {os.getcwd()}")
        print(f"Python path: {sys.path}")

        # Validate input file
        if not audio_file or not os.path.exists(audio_file):
            error_msg = f"Invalid or non-existent audio file: {audio_file}"
            print(error_msg)
            return None, error_msg

        # Ensure output directories exist
        os.makedirs("visualise/video/body-pixel2", exist_ok=True)

        # Detailed command execution
        cmd = [
            "python", 
            "scripts/demo.py",
            "--config_file", "config/body_pixel.json",
            "--infer",
            "--audio_file", audio_file,
            "--id", "0",
            "--whole_body"
        ]
        
        print(f"Executing command: {' '.join(cmd)}")

        # Run with error capture
        try:
            result = subprocess.run(
                cmd, 
                stdout=subprocess.PIPE, 
                stderr=subprocess.PIPE,
                text=True,
                timeout=600  # 10-minute timeout
            )
            
            # Log command output
            print("Command STDOUT:", result.stdout)
            print("Command STDERR:", result.stderr)

            # Check for successful execution
            if result.returncode != 0:
                error_msg = f"Command failed. STDERR: {result.stderr}"
                print(error_msg)
                return None, error_msg

        except subprocess.TimeoutExpired:
            error_msg = "Inference process timed out"
            print(error_msg)
            return None, error_msg
        except Exception as e:
            error_msg = f"Subprocess error: {str(e)}"
            print(error_msg)
            print(traceback.format_exc())
            return None, error_msg

        # Determine output video path
        audio_name = os.path.splitext(os.path.basename(audio_file))[0]
        output_dir = f"visualise/video/body-pixel2/{audio_name}"
        output_path = f"{output_dir}/1st-page.mp4"
        
        print(f"Expected output path: {output_path}")
        print(f"Output directory contents: {os.listdir(output_dir) if os.path.exists(output_dir) else 'Directory not found'}")

        # Check output video
        if os.path.exists(output_path):
            print(f"Output video found: {output_path}")
            return output_path
        else:
            error_msg = f"Output video not generated. Check script execution and paths."
            print(error_msg)
            return None, error_msg

    except Exception as e:
        error_msg = f"Unexpected error: {str(e)}"
        print(error_msg)
        print(traceback.format_exc())
        return None, error_msg

# Gradio Interface
demo = gr.Interface(
    fn=process_audio,
    inputs=gr.inputs.File(type="file", label="Upload Audio File"),
    outputs=[
        gr.outputs.Video(label="Generated Motion Video"),
        # gr.outputs.Textbox(label="Error Messages")
    ],
    title="TalkSHOW: Speech-to-Motion Translation System",
    description="Convert speech audio to realistic 3D human motion using the SMPL-X model.",
    examples=[["demo_audio/1st-page.wav"]]
)

# Launch the app
if __name__ == "__main__":
    demo.launch(
        server_name="0.0.0.0", 
        server_port=7860,
        debug=True
    )