File size: 1,605 Bytes
abfb2cd
 
 
 
 
 
0fd599c
abfb2cd
 
 
 
0fd599c
 
abfb2cd
 
0fd599c
abfb2cd
 
 
 
 
 
 
 
 
 
 
 
0fd599c
 
abfb2cd
 
 
 
 
 
 
 
 
 
 
 
 
 
257ae35
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
from lipsync import run_lipsync_pipeline
import os
from pathlib import Path


def sync(video_file, audio_file, hf_token):
    if not video_file:
        return None, "❌ Please upload a video"
    if not audio_file:
        return None, "❌ Please upload an audio file"
    if not hf_token:
        return None, "❌ Please enter your HuggingFace token"
    try:
        output_path = f"/tmp/lipsynced_{Path(video_file).stem}.mp4"
        run_lipsync_pipeline(video_file, audio_file, output_path, hf_token=hf_token)
        return output_path, "βœ… Done!"
    except Exception as e:
        import traceback
        traceback.print_exc()
        return None, f"❌ Error: {str(e)}"


demo = gr.Interface(
    fn=sync,
    inputs=[
        gr.Video(label="Original video (with visible face)"),
        gr.Audio(label="Dubbed audio (e.g. Khmer mp3/wav)", type="filepath"),
        gr.Textbox(label="HuggingFace Token", type="password",
                   info="Required for LatentSync GPU access. Get yours at huggingface.co/settings/tokens (read access is enough)"),
    ],
    outputs=[
        gr.Video(label="Lip-synced video"),
        gr.Textbox(label="Status"),
    ],
    title="🎬 Video Lip Sync",
    description=(
        "Upload a video of a speaking person and a dubbed audio track. "
        "Gets back a full video with mouth movements synced to the new audio.\n\n"
        "Powered by LatentSync (ByteDance) via remote GPU β€” no local GPU needed.\n"
        "⚠️ Long videos are processed in 8s chunks and stitched together."
    ),
)

demo.launch(ssr_mode=False)