File size: 1,041 Bytes
9892d33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import subprocess
import gdown

# Auto-download the Wav2Lip pretrained model if it doesn't exist
def download_model():
    model_url = "https://drive.google.com/uc?id=1rwXzZ1R5RkAqpKfx-9k3dxC5Pp1fSzJv"  # hosted model
    model_path = "wav2lip.pth"
    if not os.path.exists(model_path):
        gdown.download(model_url, model_path, quiet=False)
    return model_path

# Main lipsync function
def sync_lips(video, audio):
    model_path = download_model()
    output_path = "results/result_voice.mp4"
    os.makedirs("results", exist_ok=True)
    command = f"python3 inference.py --checkpoint_path {model_path} --face {video} --audio {audio} --outfile {output_path}"
    subprocess.call(command, shell=True)
    return output_path

# Gradio Interface
demo = gr.Interface(
    fn=sync_lips,
    inputs=["video", "audio"],
    outputs="video",
    title="Lip Sync Generator",
    description="Upload a face video (.mp4) and an audio file (.wav) to get a lip-synced output using Wav2Lip model."
)

demo.launch()