Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,70 +1,41 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
4 |
-
from pydub import AudioSegment
|
5 |
-
import tempfile
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
os.environ["MESA_GL_VERSION_OVERRIDE"] = "4.1"
|
10 |
-
os.system('pip install /home/user/app/pyrender')
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
24 |
-
temp_wav_path = temp_wav.name
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
try:
|
36 |
-
# Run the demo script with the specified arguments
|
37 |
-
command = [
|
38 |
-
"python", DEMO_SCRIPT_PATH,
|
39 |
-
"--config_file", CONFIG_FILE,
|
40 |
-
"--infer",
|
41 |
-
"--audio_file", wav_path,
|
42 |
-
"--body_model_name", "s2g_LS3DCG",
|
43 |
-
"--body_model_path", BODY_MODEL_PATH,
|
44 |
-
"--id", "0"
|
45 |
-
]
|
46 |
-
subprocess.run(command, check=True)
|
47 |
-
|
48 |
-
# Check if the output file exists
|
49 |
-
if os.path.exists(OUTPUT_MP4_PATH):
|
50 |
-
return OUTPUT_MP4_PATH
|
51 |
-
else:
|
52 |
-
return "Error: Output video not generated."
|
53 |
-
except subprocess.CalledProcessError as e:
|
54 |
-
return f"Error: {str(e)}"
|
55 |
-
finally:
|
56 |
-
# Clean up the temporary .wav file after processing
|
57 |
-
os.remove(wav_path)
|
58 |
-
|
59 |
-
# Define the Gradio interface
|
60 |
interface = gr.Interface(
|
61 |
-
fn=
|
62 |
-
inputs=
|
63 |
-
outputs=
|
64 |
-
title="
|
65 |
-
description="
|
66 |
)
|
67 |
|
68 |
-
# Launch the app
|
69 |
-
|
70 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
+
# Define the command template
|
6 |
+
COMMAND_TEMPLATE = "python scripts/demo.py --config_file ./config/LS3DCG.json --infer --audio_file {audio_path} --body_model_name s2g_LS3DCG --body_model_path experiments/2022-10-19-smplx_S2G-LS3DCG/ckpt-99.pth --id 0"
|
|
|
|
|
7 |
|
8 |
+
# Define the function to process the audio and generate the video
|
9 |
+
def process_audio(audio):
|
10 |
+
# Save uploaded audio to a specific file path
|
11 |
+
audio_path = "demo_audio/style.wav"
|
12 |
+
with open(audio_path, "wb") as f:
|
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 |
+
# Specify the path to the output video
|
20 |
+
output_video_path = "./output_video.mp4" # Update if output location is different
|
|
|
|
|
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 |
+
# Set up Gradio interface
|
29 |
+
audio_input = gr.Audio(label="Upload a .wav audio file", type="file")
|
30 |
+
video_output = gr.Video(label="Generated Video Output")
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
interface = gr.Interface(
|
33 |
+
fn=process_audio,
|
34 |
+
inputs=audio_input,
|
35 |
+
outputs=video_output,
|
36 |
+
title="Audio-to-Video Generator",
|
37 |
+
description="Upload a .wav file to generate an animated video output."
|
38 |
)
|
39 |
|
40 |
+
# Launch the Gradio app
|
41 |
+
interface.launch()
|
|