import gradio as gr | |
from yt_dlp import YoutubeDL | |
import os | |
def download_video(url): | |
ydl_opts = {'overwrites':True, 'format':'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', 'outtmpl':'/content/video.mp4'} | |
with YoutubeDL(ydl_opts) as ydl: | |
ydl.download(url) | |
return f"/content/video.mp4" | |
def generate(audio_in): | |
print(audio_in) | |
os.system(f"python inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face '/content/video.mp4' --audio '{audio_in}'") | |
return f"/content/Wav2Lip/results/result_voice.mp4" | |
app = gr.Blocks() | |
with app: | |
with gr.Row(): | |
with gr.Column(): | |
input_text = gr.Textbox(show_label=False, value="https://youtu.be/EU3hIXXeiz4") | |
input_download_button = gr.Button(value="Download from YouTube or Twitch") | |
audio_in = gr.Audio(show_label=False, type='filepath') | |
input_generate_button = gr.Button(value="Generate") | |
with gr.Column(): | |
video_out = gr.outputs.Video(label="Output Video") | |
input_download_button.click(download_video, inputs=[input_text], outputs=[video_out]) | |
input_generate_button.click(generate, inputs=[audio_in], outputs=[video_out]) | |
app.launch(debug=True) |