|
import gradio as gr |
|
import os |
|
import subprocess |
|
import time |
|
import traceback |
|
import sys |
|
|
|
def process_audio(audio_file): |
|
try: |
|
|
|
if isinstance(audio_file, dict): |
|
audio_file = audio_file['name'] |
|
|
|
|
|
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}") |
|
|
|
|
|
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 |
|
|
|
|
|
os.makedirs("visualise/video/body-pixel2", exist_ok=True) |
|
|
|
|
|
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)}") |
|
|
|
|
|
try: |
|
result = subprocess.run( |
|
cmd, |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.PIPE, |
|
text=True, |
|
timeout=600 |
|
) |
|
|
|
|
|
print("Command STDOUT:", result.stdout) |
|
print("Command STDERR:", result.stderr) |
|
|
|
|
|
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 |
|
|
|
|
|
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'}") |
|
|
|
|
|
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 |
|
|
|
|
|
demo = gr.Interface( |
|
fn=process_audio, |
|
inputs=gr.inputs.File(type="file", label="Upload Audio File"), |
|
outputs=[ |
|
gr.outputs.Video(label="Generated Motion Video"), |
|
|
|
], |
|
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"]] |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch( |
|
server_name="0.0.0.0", |
|
server_port=7860, |
|
debug=True |
|
) |
|
|