Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
42 |
+
fn=run_demo_and_get_video,
|
43 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
44 |
+
outputs=gr.Video()
|
45 |
+
)
|
46 |
+
|
47 |
+
# Launch the app
|
48 |
+
if __name__ == "__main__":
|
49 |
+
interface.launch()
|