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)