Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
|
|
3 |
from pydub import AudioSegment
|
|
|
4 |
|
5 |
-
#
|
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(
|
16 |
-
return
|
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 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
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()
|