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