Spaces:
Paused
Paused
Update app.py
Browse files123456789101113 unmodified lines2526272829303132333424 unmodified lines5960616263646566676869707172737475763 unmodified lines8081828384858687888990919293949596979899100101102103104105106107import osos.environ["OMP_NUM_THREADS"] = "1"import osimport subprocessfrom pathlib import Pathfrom datetime import datetimeimport gradio as grfrom huggingface_hub import snapshot_download13 unmodified lines# Clone LatentSync repo at runtime (won't appear in HF Files tab)if not REPO_DIR.exists():run(["git", "clone", "--depth", "1", "https://github.com/bytedance/LatentSync.git", str(REPO_DIR)])CKPT_DIR.mkdir(parents=True, exist_ok=True)TEMP_DIR.mkdir(parents=True, exist_ok=True)# Download all checkpoint files (includes latentsync_unet + whisper tiny/small etc)snapshot_download(repo_id=HF_CKPT_REPO,24 unmodified linesdef generate(avatar_img, audio_wav, steps, guidance, seed, use_deepcache):setup()img_path = str(Path(avatar_img).resolve())wav_path = str(Path(audio_wav).resolve())# Make a temp mp4 from the single image + audiovideo_path = make_still_video(img_path, wav_path, fps=25)out_path = TEMP_DIR / f"result_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"cmd = ["python", "-m", "scripts.inference","--unet_config_path", "configs/unet.yaml","--inference_ckpt_path", "checkpoints/latentsync_unet.pt","--video_path", video_path,"--audio_path", wav_path,3 unmodified lines"--seed", str(int(seed)),"--temp_dir", "temp",]if use_deepcache:cmd.append("--enable_deepcache")run(cmd, cwd=str(REPO_DIR))return str(out_path)with gr.Blocks(title="LatentSync (avatar.jpg + audio.wav β lip-sync mp4)") as demo:gr.Markdown("## LatentSync on Hugging Face (T4) β Upload avatar + audio β mp4")with gr.Row():avatar = gr.Image(type="filepath", label="Avatar image (jpg/png)")audio = gr.Audio(type="filepath", label="Audio (wav)", format="wav")with gr.Row():steps = gr.Slider(10, 40, value=20, step=1, label="Inference Steps")guidance = gr.Slider(0.8, 2.0, value=1.0, step=0.1, label="Guidance Scale")seed = gr.Number(value=1247, precision=0, label="Seed")deepcache = gr.Checkbox(value=True, label="Enable DeepCache (faster)")btn = gr.Button("Generate")out = gr.Video(label="Output video")btn.click(generate, inputs=[avatar, audio, steps, guidance, seed, deepcache], outputs=out)demo.launch()1234567813 unmodified lines2223242526272829303124 unmodified lines565758596061626364656667686970717273743 unmodified lines78798081828384858687888990919293949596979899100101102103104105106107import osos.environ["OMP_NUM_THREADS"] = "1"import subprocessfrom pathlib import Pathfrom datetime import datetimeimport gradio as grfrom huggingface_hub import snapshot_download13 unmodified lines# Clone LatentSync repo at runtime (won't appear in HF Files tab)if not REPO_DIR.exists():run(["git", "clone", "--depth", "1", "https://github.com/bytedance/LatentSync.git", str(REPO_DIR)])CKPT_DIR.mkdir(parents=True, exist_ok=True)TEMP_DIR.mkdir(parents=True, exist_ok=True)# Download all checkpoint files (includes latentsync_unet + whisper tiny/small etc)snapshot_download(repo_id=HF_CKPT_REPO,24 unmodified linesdef generate(avatar_img, audio_wav, steps, guidance, seed, use_deepcache):setup()img_path = str(Path(avatar_img).resolve())wav_path = str(Path(audio_wav).resolve())# Make a temp mp4 from the single image + audiovideo_path = make_still_video(img_path, wav_path, fps=25)out_path = TEMP_DIR / f"result_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"# FIXED: Use correct config path - configs/unet/stage2.yaml instead of configs/unet.yamlcmd = ["python", "-m", "scripts.inference","--unet_config_path", "configs/unet/stage2.yaml", # β FIXED PATH"--inference_ckpt_path", "checkpoints/latentsync_unet.pt","--video_path", video_path,"--audio_path", wav_path,3 unmodified lines"--seed", str(int(seed)),"--temp_dir", "temp",]if use_deepcache:cmd.append("--enable_deepcache")run(cmd, cwd=str(REPO_DIR))return str(out_path)with gr.Blocks(title="LatentSync (avatar.jpg + audio.wav β lip-sync mp4)") as demo:gr.Markdown("## LatentSync 1.5 on Hugging Face (T4) β Upload avatar + audio β mp4")with gr.Row():avatar = gr.Image(type="filepath", label="Avatar image (jpg/png)")audio = gr.Audio(type="filepath", label="Audio (wav)", format="wav")with gr.Row():steps = gr.Slider(10, 40, value=20, step=1, label="Inference Steps")guidance = gr.Slider(0.8, 2.0, value=1.0, step=0.1, label="Guidance Scale")seed = gr.Number(value=1247, precision=0, label="Seed")deepcache = gr.Checkbox(value=True, label="Enable DeepCache (faster)")btn = gr.Button("Generate")out = gr.Video(label="Output video")btn.click(generate, inputs=[avatar, audio, steps, guidance, seed, deepcache], outputs=out)demo.launch()
app.py+17-17