TALKSHOW / app.py
shipra-99's picture
Update app.py
068ba96 verified
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
)