Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import gdown
|
| 5 |
+
|
| 6 |
+
# Auto-download the Wav2Lip pretrained model if it doesn't exist
|
| 7 |
+
def download_model():
|
| 8 |
+
model_url = 'https://drive.google.com/uc?id=1rwXzZ1R5RkAqpKfx-9k3dxC5Pp1fSzJv'
|
| 9 |
+
model_path = "wav2lip.pth"
|
| 10 |
+
if not os.path.exists(model_path):
|
| 11 |
+
gdown.download(model_url, model_path, quiet=False)
|
| 12 |
+
return model_path
|
| 13 |
+
|
| 14 |
+
# Main lipsync function
|
| 15 |
+
def sync_lips(video, audio):
|
| 16 |
+
model_path = download_model()
|
| 17 |
+
output_path = "results/result_voice.mp4"
|
| 18 |
+
os.makedirs("results", exist_ok=True)
|
| 19 |
+
command = f"python3 inference.py --checkpoint_path {model_path} --face {video} --audio {audio} --outfile {output_path}"
|
| 20 |
+
subprocess.call(command, shell=True)
|
| 21 |
+
return output_path
|
| 22 |
+
|
| 23 |
+
# Gradio Interface
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=sync_lips,
|
| 26 |
+
inputs=["video", "audio"],
|
| 27 |
+
outputs="video",
|
| 28 |
+
title="Lip Sync Generator",
|
| 29 |
+
description="Upload a face video (.mp4) and an audio file (.wav) to get a lip-synced output using Wav2Lip model."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|