Spaces:
Sleeping
Sleeping
insanecoder69
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,73 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
f.write(audio.read())
|
14 |
|
15 |
-
# Run the script command with the specified audio file
|
16 |
-
command = COMMAND_TEMPLATE.format(audio_path=audio_path)
|
17 |
-
subprocess.run(command, shell=True)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
# Check if the video file exists and return it for display
|
23 |
-
if os.path.exists(output_video_path):
|
24 |
-
return output_video_path
|
25 |
-
else:
|
26 |
-
return "Error: Video file not generated."
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
interface = gr.Interface(
|
33 |
-
fn=
|
34 |
-
inputs=
|
35 |
-
outputs=
|
36 |
-
title="
|
37 |
-
description="
|
38 |
)
|
39 |
|
40 |
-
# Launch the
|
41 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
4 |
+
from pydub import AudioSegment
|
5 |
+
import tempfile
|
6 |
|
7 |
+
# Set OpenGL platform
|
8 |
+
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
9 |
+
os.environ["MESA_GL_VERSION_OVERRIDE"] = "4.1"
|
10 |
+
os.system('pip install /home/user/app/pyrender')
|
11 |
|
12 |
+
# Paths to TalkShow demo script and configuration
|
13 |
+
DEMO_SCRIPT_PATH = "scripts/demo.py"
|
14 |
+
CONFIG_FILE = "./config/LS3DCG.json"
|
15 |
+
BODY_MODEL_PATH = "experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth"
|
16 |
+
OUTPUT_MP4_PATH = "./output/demo_output.mp4"
|
|
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
+
# Ensure the output directory exists
|
20 |
+
os.makedirs(os.path.dirname(OUTPUT_MP4_PATH), exist_ok=True)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
def convert_audio_to_wav(input_audio):
|
24 |
+
# Use a temporary file to save the .wav output
|
25 |
+
temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
26 |
+
temp_wav_path = temp_wav.name
|
27 |
|
28 |
+
# Convert the input audio to .wav format
|
29 |
+
audio = AudioSegment.from_file(input_audio)
|
30 |
+
audio.export(temp_wav_path, format="wav")
|
31 |
+
return temp_wav_path
|
32 |
+
|
33 |
+
|
34 |
+
def run_demo_and_get_video(input_audio):
|
35 |
+
# Convert the input audio to a temporary .wav file
|
36 |
+
wav_path = convert_audio_to_wav(input_audio)
|
37 |
+
|
38 |
+
try:
|
39 |
+
# Run the demo script with the specified arguments
|
40 |
+
command = [
|
41 |
+
"python", DEMO_SCRIPT_PATH,
|
42 |
+
"--config_file", CONFIG_FILE,
|
43 |
+
"--infer",
|
44 |
+
"--audio_file", wav_path,
|
45 |
+
"--body_model_name", "s2g_LS3DCG",
|
46 |
+
"--body_model_path", BODY_MODEL_PATH,
|
47 |
+
"--id", "0"
|
48 |
+
]
|
49 |
+
subprocess.run(command, check=True)
|
50 |
+
|
51 |
+
# Check if the output file exists
|
52 |
+
if os.path.exists(OUTPUT_MP4_PATH):
|
53 |
+
return OUTPUT_MP4_PATH
|
54 |
+
else:
|
55 |
+
return "Error: Output video not generated."
|
56 |
+
except subprocess.CalledProcessError as e:
|
57 |
+
return f"Error: {str(e)}"
|
58 |
+
finally:
|
59 |
+
# Clean up the temporary .wav file after processing
|
60 |
+
os.remove(wav_path)
|
61 |
+
|
62 |
+
# Define the Gradio interface
|
63 |
interface = gr.Interface(
|
64 |
+
fn=run_demo_and_get_video,
|
65 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
66 |
+
outputs=gr.Video(type="file"),
|
67 |
+
title="TalkSHOW Demo",
|
68 |
+
description="Generate a video from audio input using TalkSHOW model."
|
69 |
)
|
70 |
|
71 |
+
# Launch the app
|
72 |
+
if __name__ == "__main__":
|
73 |
+
interface.launch()
|