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) |