shipra-99 commited on
Commit
995b11a
·
verified ·
1 Parent(s): 4c4a0d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -54
app.py CHANGED
@@ -2,97 +2,113 @@ import gradio as gr
2
  import os
3
  import subprocess
4
  import time
5
- import logging
6
  import traceback
 
7
 
8
  def process_audio(audio_file):
9
- # Configure detailed logging
10
- logging.basicConfig(level=logging.DEBUG,
11
- format='%(asctime)s - %(levelname)s - %(message)s')
12
- logger = logging.getLogger(__name__)
13
-
14
  try:
15
- # Detailed logging for input
16
- logger.info(f"Received audio file: {audio_file}")
17
- logger.info(f"Audio file exists: {os.path.exists(audio_file)}")
18
-
 
 
 
 
 
 
19
  # Validate input file
20
  if not audio_file or not os.path.exists(audio_file):
21
- raise ValueError(f"Invalid or non-existent audio file: {audio_file}")
 
 
22
 
23
- # Ensure output directory exists
24
  os.makedirs("visualise/video/body-pixel2", exist_ok=True)
25
-
26
- # Debugging: print current working directory and file details
27
- logger.debug(f"Current working directory: {os.getcwd()}")
28
- logger.debug(f"Audio file path: {os.path.abspath(audio_file)}")
29
- logger.debug(f"Audio file size: {os.path.getsize(audio_file)} bytes")
30
 
31
- # Construct command with full paths
32
  cmd = [
33
  "python",
34
- os.path.abspath("scripts/demo.py"),
35
- "--config_file", os.path.abspath("config/body_pixel.json"),
36
  "--infer",
37
- "--audio_file", os.path.abspath(audio_file),
38
  "--id", "0",
39
  "--whole_body"
40
  ]
41
 
42
- logger.info(f"Executing command: {' '.join(cmd)}")
43
-
44
- # Run with more detailed error capture
45
- result = subprocess.run(
46
- cmd,
47
- stdout=subprocess.PIPE,
48
- stderr=subprocess.PIPE,
49
- text=True,
50
- cwd=os.getcwd(), # Ensure correct working directory
51
- timeout=1800
52
- )
53
-
54
- # Log full command output
55
- logger.info(f"Command STDOUT: {result.stdout}")
56
- logger.error(f"Command STDERR: {result.stderr}")
57
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  # Determine output video path
59
  audio_name = os.path.splitext(os.path.basename(audio_file))[0]
60
  output_dir = f"visualise/video/body-pixel2/{audio_name}"
61
  output_path = f"{output_dir}/1st-page.mp4"
62
 
63
- logger.info(f"Expected output path: {output_path}")
64
-
 
65
  # Check output video
66
  if os.path.exists(output_path):
67
- logger.info(f"Output video found: {output_path}")
68
  return output_path
69
  else:
70
- logger.error("Output video not generated")
71
- return None, f"Error: Output video not generated. STDERR: {result.stderr}"
72
-
73
- except subprocess.TimeoutExpired:
74
- logger.error("Inference process timed out")
75
- return None, "Error: Inference process took too long"
76
-
77
  except Exception as e:
78
- logger.error(f"Unexpected error: {str(e)}")
79
- logger.error(traceback.format_exc())
80
- return None, f"Unexpected error: {str(e)}"
 
81
 
82
- # Gradio Interface for 3.x compatibility
83
  demo = gr.Interface(
84
  fn=process_audio,
85
  inputs=gr.inputs.File(type="file", label="Upload Audio File"),
86
- outputs=gr.outputs.Video(label="Generated Motion Video"),
 
 
 
87
  title="TalkSHOW: Speech-to-Motion Translation System",
88
  description="Convert speech audio to realistic 3D human motion using the SMPL-X model.",
89
  examples=[["demo_audio/1st-page.wav"]]
90
  )
91
 
92
- # Launch with comprehensive logging
93
  if __name__ == "__main__":
94
  demo.launch(
95
  server_name="0.0.0.0",
96
  server_port=7860,
97
- debug=True # Enable Gradio debug mode
98
  )
 
2
  import os
3
  import subprocess
4
  import time
 
5
  import traceback
6
+ import sys
7
 
8
  def process_audio(audio_file):
 
 
 
 
 
9
  try:
10
+ # Ensure input is a valid filepath for Gradio 3.x
11
+ if isinstance(audio_file, dict):
12
+ audio_file = audio_file['name']
13
+
14
+ # Comprehensive error logging
15
+ print(f"Processing audio file: {audio_file}")
16
+ print(f"File exists: {os.path.exists(audio_file)}")
17
+ print(f"Current working directory: {os.getcwd()}")
18
+ print(f"Python path: {sys.path}")
19
+
20
  # Validate input file
21
  if not audio_file or not os.path.exists(audio_file):
22
+ error_msg = f"Invalid or non-existent audio file: {audio_file}"
23
+ print(error_msg)
24
+ return None, error_msg
25
 
26
+ # Ensure output directories exist
27
  os.makedirs("visualise/video/body-pixel2", exist_ok=True)
 
 
 
 
 
28
 
29
+ # Detailed command execution
30
  cmd = [
31
  "python",
32
+ "scripts/demo.py",
33
+ "--config_file", "config/body_pixel.json",
34
  "--infer",
35
+ "--audio_file", audio_file,
36
  "--id", "0",
37
  "--whole_body"
38
  ]
39
 
40
+ print(f"Executing command: {' '.join(cmd)}")
41
+
42
+ # Run with error capture
43
+ try:
44
+ result = subprocess.run(
45
+ cmd,
46
+ stdout=subprocess.PIPE,
47
+ stderr=subprocess.PIPE,
48
+ text=True,
49
+ timeout=600 # 10-minute timeout
50
+ )
51
+
52
+ # Log command output
53
+ print("Command STDOUT:", result.stdout)
54
+ print("Command STDERR:", result.stderr)
55
+
56
+ # Check for successful execution
57
+ if result.returncode != 0:
58
+ error_msg = f"Command failed. STDERR: {result.stderr}"
59
+ print(error_msg)
60
+ return None, error_msg
61
+
62
+ except subprocess.TimeoutExpired:
63
+ error_msg = "Inference process timed out"
64
+ print(error_msg)
65
+ return None, error_msg
66
+ except Exception as e:
67
+ error_msg = f"Subprocess error: {str(e)}"
68
+ print(error_msg)
69
+ print(traceback.format_exc())
70
+ return None, error_msg
71
+
72
  # Determine output video path
73
  audio_name = os.path.splitext(os.path.basename(audio_file))[0]
74
  output_dir = f"visualise/video/body-pixel2/{audio_name}"
75
  output_path = f"{output_dir}/1st-page.mp4"
76
 
77
+ print(f"Expected output path: {output_path}")
78
+ print(f"Output directory contents: {os.listdir(output_dir) if os.path.exists(output_dir) else 'Directory not found'}")
79
+
80
  # Check output video
81
  if os.path.exists(output_path):
82
+ print(f"Output video found: {output_path}")
83
  return output_path
84
  else:
85
+ error_msg = f"Output video not generated. Check script execution and paths."
86
+ print(error_msg)
87
+ return None, error_msg
88
+
 
 
 
89
  except Exception as e:
90
+ error_msg = f"Unexpected error: {str(e)}"
91
+ print(error_msg)
92
+ print(traceback.format_exc())
93
+ return None, error_msg
94
 
95
+ # Gradio Interface
96
  demo = gr.Interface(
97
  fn=process_audio,
98
  inputs=gr.inputs.File(type="file", label="Upload Audio File"),
99
+ outputs=[
100
+ gr.outputs.Video(label="Generated Motion Video"),
101
+ gr.outputs.Textbox(label="Error Messages")
102
+ ],
103
  title="TalkSHOW: Speech-to-Motion Translation System",
104
  description="Convert speech audio to realistic 3D human motion using the SMPL-X model.",
105
  examples=[["demo_audio/1st-page.wav"]]
106
  )
107
 
108
+ # Launch the app
109
  if __name__ == "__main__":
110
  demo.launch(
111
  server_name="0.0.0.0",
112
  server_port=7860,
113
+ debug=True
114
  )