Spaces:
Runtime error
Update app.py
Browse filesfrom transformers import pipeline
import soundfile as sf
from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
from PIL import Image, ImageDraw, ImageFont
import numpy as np
# ===== 1️⃣ Criar TTS =====
tts_model = pipeline(
"text-to-speech",
model="espnet/kan-bayashi_ljspeech_tts_train_tacotron2"
)
texto = "Olá! Este é um teste de geração de áudio e vídeo."
# ===== 2️⃣ Gerar áudio =====
output = tts_model(texto)
sf.write("saida.wav", output["array"], samplerate=output["sampling_rate"])
# ===== 3️⃣ Criar imagem de fundo =====
largura, altura = 1280, 720
img = Image.new('RGB', (largura, altura), color=(30, 30, 30))
draw = ImageDraw.Draw(img)
font = ImageFont.load_default()
draw.text((50, altura//2 - 10), texto, fill=(255, 255, 255), font=font)
img.save("background.png")
# ===== 4️⃣ Criar clipe de vídeo =====
audio_clip = AudioFileClip("saida.wav")
image_clip = ImageClip("background.png").set_duration(audio_clip.duration)
video_clip = image_clip.set_audio(audio_clip)
# ===== 5️⃣ Salvar vídeo =====
video_clip.write_videofile("saida.mp4", fps=24)
print("Vídeo gerado com sucesso! Verifique o arquivo 'saida.mp4'.")
|
@@ -1,44 +1,35 @@
|
|
| 1 |
-
# app_hf_space.py
|
| 2 |
-
import gradio as gr
|
| 3 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
# Pipeline de TTS (opcional, caso queira gerar áudio separado)
|
| 7 |
tts_model = pipeline(
|
| 8 |
"text-to-speech",
|
| 9 |
-
model="espnet/kan-
|
| 10 |
)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
video_model = pipeline(
|
| 14 |
-
"text-to-video",
|
| 15 |
-
model="Wan-AI/Wan2.2-T2V-A14B"
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
Gera vídeo a partir do texto usando o modelo Wan2.2.
|
| 22 |
-
O pipeline retorna vídeo final, pronto para Gradio.
|
| 23 |
-
"""
|
| 24 |
-
# Gera vídeo (até 60 segundos)
|
| 25 |
-
video_out = video_model(prompt, max_length=60)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
lines=2,
|
| 35 |
-
placeholder="Digite o texto para gerar vídeo..."
|
| 36 |
-
),
|
| 37 |
-
outputs=gr.Video(label="Vídeo Gerado"),
|
| 38 |
-
title="Gerador Multimodal de Vídeo AI",
|
| 39 |
-
description="Digite um texto e receba um vídeo gerado diretamente pelo modelo AI."
|
| 40 |
-
)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
import soundfile as sf
|
| 3 |
+
from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
|
| 4 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
+
# ===== 1️⃣ Criar TTS =====
|
|
|
|
| 8 |
tts_model = pipeline(
|
| 9 |
"text-to-speech",
|
| 10 |
+
model="espnet/kan-bayashi_ljspeech_tts_train_tacotron2"
|
| 11 |
)
|
| 12 |
|
| 13 |
+
texto = "Olá! Este é um teste de geração de áudio e vídeo."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# ===== 2️⃣ Gerar áudio =====
|
| 16 |
+
output = tts_model(texto)
|
| 17 |
+
sf.write("saida.wav", output["array"], samplerate=output["sampling_rate"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# ===== 3️⃣ Criar imagem de fundo =====
|
| 20 |
+
largura, altura = 1280, 720
|
| 21 |
+
img = Image.new('RGB', (largura, altura), color=(30, 30, 30))
|
| 22 |
+
draw = ImageDraw.Draw(img)
|
| 23 |
+
font = ImageFont.load_default()
|
| 24 |
+
draw.text((50, altura//2 - 10), texto, fill=(255, 255, 255), font=font)
|
| 25 |
+
img.save("background.png")
|
| 26 |
|
| 27 |
+
# ===== 4️⃣ Criar clipe de vídeo =====
|
| 28 |
+
audio_clip = AudioFileClip("saida.wav")
|
| 29 |
+
image_clip = ImageClip("background.png").set_duration(audio_clip.duration)
|
| 30 |
+
video_clip = image_clip.set_audio(audio_clip)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# ===== 5️⃣ Salvar vídeo =====
|
| 33 |
+
video_clip.write_videofile("saida.mp4", fps=24)
|
| 34 |
|
| 35 |
+
print("Vídeo gerado com sucesso! Verifique o arquivo 'saida.mp4'.")
|