File size: 1,190 Bytes
a470e25
9fbf741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
β€Žimport os
β€Ž
β€Ž
β€Ždef generate_lipsync(image, audio):
β€Ž    os.makedirs("input", exist_ok=True)
β€Ž    os.makedirs("output", exist_ok=True)
β€Ž
β€Ž    image_path = "input/image.jpg"
β€Ž    audio_path = "input/audio.wav"
β€Ž    video_path = "input/video.mp4"
β€Ž    result_path = "output/result_voice.mp4"
β€Ž
β€Ž    image.save(image_path)
β€Ž
β€Ž    os.system(f"cp '{audio}' {audio_path}")
β€Ž
β€Ž    os.system(
β€Ž        f"ffmpeg -loop 1 -i {image_path} -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=512:512 {video_path} -y"
β€Ž    )
β€Ž
β€Ž    command = f'''
β€Ž    python wav2lip/inference.py \
β€Ž    --checkpoint_path checkpoints/wav2lip_gan.pth \
β€Ž    --face {video_path} \
β€Ž    --audio {audio_path} \
β€Ž    --outfile {result_path}
β€Ž    '''
β€Ž
β€Ž    os.system(command)
β€Ž
β€Ž    return result_path
β€Ž
β€Ž
β€Žiface = gr.Interface(
β€Ž    fn=generate_lipsync,
β€Ž    inputs=[
β€Ž        gr.Image(type="pil", label="Upload Image"),
β€Ž        gr.Audio(type="filepath", label="Upload Audio")
β€Ž    ],
β€Ž    outputs=gr.Video(label="Generated Video"),
β€Ž    title="TikTok AI LipSync"
β€Ž)
β€Ž
β€Žiface.launch(server_name="0.0.0.0", server_port=7860)