Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,13 @@ import tempfile
|
|
| 5 |
import time
|
| 6 |
import shutil
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
-
from moviepy.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import edge_tts
|
| 10 |
import gradio as gr
|
| 11 |
|
|
@@ -75,9 +81,14 @@ def create_video_with_text(text, duration, size=(1280, 720)):
|
|
| 75 |
# Fondo del video
|
| 76 |
bg_clip = ColorClip(size, color=(30, 30, 30), duration=duration)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
# Texto con ajuste autom谩tico de tama帽o
|
| 79 |
text_clip = TextClip(
|
| 80 |
-
text,
|
| 81 |
fontsize=28,
|
| 82 |
color='white',
|
| 83 |
font='Arial-Bold',
|
|
@@ -86,9 +97,16 @@ def create_video_with_text(text, duration, size=(1280, 720)):
|
|
| 86 |
align='center'
|
| 87 |
).set_position('center').set_duration(duration)
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
logger.error(f"Error al crear video con texto: {e}")
|
|
|
|
|
|
|
| 92 |
raise
|
| 93 |
|
| 94 |
async def generate_video_content(text, background_music=None, use_tts=True):
|
|
|
|
| 5 |
import time
|
| 6 |
import shutil
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
+
from moviepy.config import change_settings
|
| 9 |
+
|
| 10 |
+
# Configura ImageMagick antes de otros imports
|
| 11 |
+
change_settings({"IMAGEMAGICK_BINARY": "/usr/bin/convert"})
|
| 12 |
+
|
| 13 |
+
# Ahora importa los componentes de MoviePy
|
| 14 |
+
from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip, ColorClip, TextClip, CompositeVideoClip, concatenate_audioclips
|
| 15 |
import edge_tts
|
| 16 |
import gradio as gr
|
| 17 |
|
|
|
|
| 81 |
# Fondo del video
|
| 82 |
bg_clip = ColorClip(size, color=(30, 30, 30), duration=duration)
|
| 83 |
|
| 84 |
+
# Configuraci贸n segura para TextClip
|
| 85 |
+
temp_txt = os.path.join(TEMP_DIR, f"temp_text_{datetime.now().strftime('%Y%m%d%H%M%S')}.txt")
|
| 86 |
+
with open(temp_txt, 'w', encoding='utf-8') as f:
|
| 87 |
+
f.write(text)
|
| 88 |
+
|
| 89 |
# Texto con ajuste autom谩tico de tama帽o
|
| 90 |
text_clip = TextClip(
|
| 91 |
+
txt=text,
|
| 92 |
fontsize=28,
|
| 93 |
color='white',
|
| 94 |
font='Arial-Bold',
|
|
|
|
| 97 |
align='center'
|
| 98 |
).set_position('center').set_duration(duration)
|
| 99 |
|
| 100 |
+
video = CompositeVideoClip([bg_clip, text_clip])
|
| 101 |
+
|
| 102 |
+
# Eliminar archivo temporal de texto
|
| 103 |
+
os.remove(temp_txt)
|
| 104 |
+
|
| 105 |
+
return video
|
| 106 |
except Exception as e:
|
| 107 |
logger.error(f"Error al crear video con texto: {e}")
|
| 108 |
+
if os.path.exists(temp_txt):
|
| 109 |
+
os.remove(temp_txt)
|
| 110 |
raise
|
| 111 |
|
| 112 |
async def generate_video_content(text, background_music=None, use_tts=True):
|