TalkSHOWLIVE / app.py
insanecoder69's picture
Create app.py
1b8d40c verified
raw
history blame
1.45 kB
import gradio as gr
import subprocess
from pydub import AudioSegment
# Path to the 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"
STYLE_WAV_PATH = "./demo_audio/style.wav"
def convert_audio_to_wav(input_audio):
# Convert the input audio to .wav format
audio = AudioSegment.from_file(input_audio)
audio.export(STYLE_WAV_PATH, format="wav")
return STYLE_WAV_PATH
def run_demo_and_get_video(input_audio):
# Convert the input audio to .wav
wav_path = convert_audio_to_wav(input_audio)
# 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."
# 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()