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