Spaces:
Build error
Build error
File size: 1,435 Bytes
3184c99 72c4f84 3184c99 |
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 46 47 48 49 50 51 |
import gradio as gr
import os
import subprocess
from gtts import gTTS
from pydub import AudioSegment
def generate_video(image, text):
# Save input image
image_path = "input.jpg"
image.save(image_path)
# Create 5 sec mute video from image
cmd = [
"ffmpeg", "-y", "-loop", "1", "-i", image_path,
"-t", "5", "-vf", "fps=25,scale=512:512",
"-c:v", "libx264", "-pix_fmt", "yuv420p", "input.mp4"
]
subprocess.run(cmd, check=True)
# Generate audio from text using gTTS
tts = gTTS(text, lang="en")
tts.save("tts.mp3")
AudioSegment.from_mp3("tts.mp3").export("tts.wav", format="wav")
# Run Wav2Lip inference
cmd = [
"python", "Wav2Lip/inference.py",
"--checkpoint_path", "checkpoints/wav2lip.pth",
"--face", "input.mp4",
"--audio", "tts.wav",
"--outfile", "output.mp4"
]
subprocess.run(cmd, check=True)
return "output.mp4"
# Build Gradio interface
iface = gr.Interface(
fn=generate_video,
inputs=[
gr.Image(type="pil", label="Upload Cartoon Image"),
gr.Textbox(lines=2, placeholder="Enter text for speech...", label="Text to Speak")
],
outputs=gr.Video(label="Talking Cartoon Video"),
title="Cartoon Talking Video Generator",
description="Upload a cartoon image and enter text to generate a talking video using Wav2Lip."
)
if __name__ == "__main__":
iface.launch()
|