Spaces:
Build error
Build error
import gradio as gr | |
import subprocess | |
import ffmpeg | |
def convert_video(input_file, output_file, format='mp4'): | |
try: | |
# Define input and output files | |
input_path = input_file | |
output_path = output_file + '.' + format | |
# Define ffmpeg command | |
ffmpeg_cmd = ( | |
ffmpeg | |
.input(input_path) | |
.output(output_path, vcodec='libx264', acodec='aac') | |
.run() | |
) | |
print(f"Video converted successfully: {output_path}") | |
except Exception as e: | |
print(f"Error converting video: {e}") | |
def execute_command(command: str) -> None: | |
subprocess.run(command, check=True) | |
def infer(): | |
output_name = "acknowledgement_english@M030_front_neutral_level1_001@male_face" | |
command = [ | |
f"python", | |
f"inference_for_demo_video.py", | |
f"--wav_path=data/audio/acknowledgement_english.m4a", | |
f"--style_clip_path=data/style_clip/3DMM/M030_front_neutral_level1_001.mat", | |
f"--pose_path=data/pose/RichardShelby_front_neutral_level1_001.mat", | |
f"--image_path=data/src_img/uncropped/male_face.png", | |
f"--cfg_scale=1.0", | |
f"--max_gen_len=30", | |
f"--output_name={output_name}" | |
] | |
execute_command(command) | |
# Convert video to compatible codecs | |
input_file_path = f"output_video/{output_name}.mp4" | |
output_file_path = f"{output_name}" | |
convert_video(input_file_path, output_file_path) | |
return f"{output_file_path}.mp4" | |
with gr.Blocks() as demo: | |
with gr.Column(): | |
with gr.Row(): | |
with gr.Column(): | |
run_btn = gr.Button("Run") | |
with gr.Column(): | |
output_video = gr.Video() | |
run_btn.click( | |
fn = infer, | |
inputs = [], | |
outputs = [output_video] | |
) | |
demo.launch() |