Spaces:
Sleeping
Sleeping
Create modules/video_maker.py
Browse files- modules/video_maker.py +125 -0
modules/video_maker.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Módulo creador de videos reels/TikTok.
|
| 3 |
+
Usa MoviePy para edición básica (opcional).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import tempfile
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
def create_reel_from_images(image_paths, duration_per_image=2,
|
| 10 |
+
total_duration=None, music_track="chill"):
|
| 11 |
+
"""
|
| 12 |
+
Crea video reel a partir de imágenes.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
image_paths: Lista de rutas a imágenes
|
| 18 |
+
duration_per_image: Segundos por imagen
|
| 19 |
+
total_duration: Duración total deseada (si None, usa todas)
|
| 20 |
+
music_track: Tipo de música ("chill", "energetic", "romantic")
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
str: Ruta al archivo de video creado
|
| 24 |
+
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
# ====== IMPLEMENTACIÓN PLACEHOLDER ======
|
| 28 |
+
# Aquí conectarías MoviePy o similar para crear video real
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
print(f"Creando reel con {len(image_paths)} imágenes...")
|
| 32 |
+
|
| 33 |
+
# Crear archivo de video placeholder (texto en negro)
|
| 34 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 35 |
+
|
| 36 |
+
# Dimensiones estándar TikTok/Reel (vertical 9:16)
|
| 37 |
+
width, height = 1080, 1920
|
| 38 |
+
|
| 39 |
+
# Crear imagen negra con texto
|
| 40 |
+
img = Image.new('RGB', (width, height), color=(0, 0, 0))
|
| 41 |
+
|
| 42 |
+
draw = ImageDraw.Draw(img)
|
| 43 |
+
|
| 44 |
+
# Texto informativo
|
| 45 |
+
text_lines = [
|
| 46 |
+
"🎬 VIDEO REEL SOFÍA RIVERA",
|
| 47 |
+
f"Imágenes: {len(image_paths)}",
|
| 48 |
+
f"Duración por imagen: {duration_per_image}s",
|
| 49 |
+
f"Música: {music_track}",
|
| 50 |
+
"",
|
| 51 |
+
|
| 52 |
+
"✨ Implementa MoviePy aquí ✨",
|
| 53 |
+
"",
|
| 54 |
+
"Para video real:",
|
| 55 |
+
"1. pip install moviepy",
|
| 56 |
+
"2. Conectar con tu modelo de IA"
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
# Intentar usar fuente más grande
|
| 60 |
+
try:
|
| 61 |
+
|
| 62 |
+
font = ImageFont.truetype("arial.ttf", 40)
|
| 63 |
+
except:
|
| 64 |
+
font = ImageFont.load_default()
|
| 65 |
+
|
| 66 |
+
# Dibujar líneas de texto
|
| 67 |
+
y_position = height // 4
|
| 68 |
+
|
| 69 |
+
for line in text_lines:
|
| 70 |
+
# Calcular ancho texto para centrar
|
| 71 |
+
if hasattr(font, 'getbbox'):
|
| 72 |
+
bbox = font.getbbox(line)
|
| 73 |
+
text_width = bbox[2] - bbox[0]
|
| 74 |
+
|
| 75 |
+
else:
|
| 76 |
+
text_width = len(line) * 20
|
| 77 |
+
|
| 78 |
+
x_position = (width - text_width) // 2
|
| 79 |
+
|
| 80 |
+
draw.text((x_position, y_position),
|
| 81 |
+
line,
|
| 82 |
+
fill=(255, 105, 180), # Rosa Sofía
|
| 83 |
+
font=font)
|
| 84 |
+
|
| 85 |
+
y_position += 60
|
| 86 |
+
|
| 87 |
+
# Guardar como video placeholder (en realidad es imagen)
|
| 88 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
| 89 |
+
|
| 90 |
+
# Convertir imagen a video (placeholder simple)
|
| 91 |
+
img.save(temp_file.name.replace('.mp4', '.jpg'))
|
| 92 |
+
|
| 93 |
+
# Renombrar extensión para que Gradio lo reconozca como video
|
| 94 |
+
os.rename(temp_file.name.replace('.mp4', '.jpg'), temp_file.name)
|
| 95 |
+
|
| 96 |
+
print(f"Video placeholder creado: {temp_file.name}")
|
| 97 |
+
|
| 98 |
+
return temp_file.name
|
| 99 |
+
|
| 100 |
+
except Exception as e:
|
| 101 |
+
print(f"Error creando video: {e}")
|
| 102 |
+
|
| 103 |
+
# Fallback: archivo vacío
|
| 104 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
| 105 |
+
|
| 106 |
+
with open(temp_file.name, 'wb') as f:
|
| 107 |
+
f.write(b"") # Archivo vacío
|
| 108 |
+
|
| 109 |
+
return temp_file.name
|
| 110 |
+
|
| 111 |
+
def add_music_to_video(video_path, music_track="chill"):
|
| 112 |
+
"""Añade música a video (placeholder)"""
|
| 113 |
+
|
| 114 |
+
return video_path # Implementar con MoviePy
|
| 115 |
+
|
| 116 |
+
def get_free_music_tracks():
|
| 117 |
+
"""Devuelve lista de pistas musicales gratuitas"""
|
| 118 |
+
|
| 119 |
+
return [
|
| 120 |
+
{"name": "Chill Vibes", "genre": "Lo-fi", "duration": 30},
|
| 121 |
+
{"name": "Energetic Pop", "genre": "Pop", "duration": 25},
|
| 122 |
+
|
| 123 |
+
{"name": "Romantic Piano", "genre": "Classical", "duration": 40},
|
| 124 |
+
{"name": "Summer Beats", "genre": "Electronic", "duration": 35}
|
| 125 |
+
]
|