insanecoder69 commited on
Commit
9e6f4e1
·
verified ·
1 Parent(s): 1b8d40c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -1,41 +1,50 @@
1
  import gradio as gr
2
  import subprocess
 
3
  from pydub import AudioSegment
 
4
 
5
- # Path to the TalkShow demo script and configuration
6
  DEMO_SCRIPT_PATH = "scripts/demo.py"
7
  CONFIG_FILE = "./config/LS3DCG.json"
8
  BODY_MODEL_PATH = "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth"
9
  OUTPUT_MP4_PATH = "./output/demo_output.mp4"
10
- STYLE_WAV_PATH = "./demo_audio/style.wav"
11
 
12
  def convert_audio_to_wav(input_audio):
 
 
 
 
13
  # Convert the input audio to .wav format
14
  audio = AudioSegment.from_file(input_audio)
15
- audio.export(STYLE_WAV_PATH, format="wav")
16
- return STYLE_WAV_PATH
17
 
18
  def run_demo_and_get_video(input_audio):
19
- # Convert the input audio to .wav
20
  wav_path = convert_audio_to_wav(input_audio)
21
 
22
- # Run the demo script with the specified arguments
23
- command = [
24
- "python", DEMO_SCRIPT_PATH,
25
- "--config_file", CONFIG_FILE,
26
- "--infer",
27
- "--audio_file", wav_path,
28
- "--body_model_name", "s2g_LS3DCG",
29
- "--body_model_path", BODY_MODEL_PATH,
30
- "--id", "0"
31
- ]
32
- subprocess.run(command, check=True)
33
-
34
- # Check if the output file exists
35
- if os.path.exists(OUTPUT_MP4_PATH):
36
- return OUTPUT_MP4_PATH
37
- else:
38
- return "Error: Output video not generated."
 
 
 
 
39
 
40
  # Define the Gradio interface
41
  interface = gr.Interface(
@@ -46,4 +55,4 @@ interface = gr.Interface(
46
 
47
  # Launch the app
48
  if __name__ == "__main__":
49
- interface.launch()
 
1
  import gradio as gr
2
  import subprocess
3
+ import os
4
  from pydub import AudioSegment
5
+ import tempfile
6
 
7
+ # Paths to TalkShow demo script and configuration
8
  DEMO_SCRIPT_PATH = "scripts/demo.py"
9
  CONFIG_FILE = "./config/LS3DCG.json"
10
  BODY_MODEL_PATH = "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth"
11
  OUTPUT_MP4_PATH = "./output/demo_output.mp4"
 
12
 
13
  def convert_audio_to_wav(input_audio):
14
+ # Use a temporary file to save the .wav output
15
+ temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
16
+ temp_wav_path = temp_wav.name
17
+
18
  # Convert the input audio to .wav format
19
  audio = AudioSegment.from_file(input_audio)
20
+ audio.export(temp_wav_path, format="wav")
21
+ return temp_wav_path
22
 
23
  def run_demo_and_get_video(input_audio):
24
+ # Convert the input audio to a temporary .wav file
25
  wav_path = convert_audio_to_wav(input_audio)
26
 
27
+ try:
28
+ # Run the demo script with the specified arguments
29
+ command = [
30
+ "python", DEMO_SCRIPT_PATH,
31
+ "--config_file", CONFIG_FILE,
32
+ "--infer",
33
+ "--audio_file", wav_path,
34
+ "--body_model_name", "s2g_LS3DCG",
35
+ "--body_model_path", BODY_MODEL_PATH,
36
+ "--id", "0"
37
+ ]
38
+ subprocess.run(command, check=True)
39
+
40
+ # Check if the output file exists
41
+ if os.path.exists(OUTPUT_MP4_PATH):
42
+ return OUTPUT_MP4_PATH
43
+ else:
44
+ return "Error: Output video not generated."
45
+ finally:
46
+ # Clean up the temporary .wav file after processing
47
+ os.remove(wav_path)
48
 
49
  # Define the Gradio interface
50
  interface = gr.Interface(
 
55
 
56
  # Launch the app
57
  if __name__ == "__main__":
58
+ interface.launch()