Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,13 @@ from datetime import datetime
|
|
10 |
import numpy as np
|
11 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
12 |
import nltk
|
13 |
-
from nltk.tokenize import sent_tokenize
|
14 |
import random
|
15 |
from transformers import pipeline
|
16 |
import torch
|
|
|
17 |
|
18 |
# Configuraci贸n inicial
|
19 |
-
nltk.download('punkt')
|
20 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
21 |
logger = logging.getLogger(__name__)
|
22 |
|
@@ -25,7 +25,7 @@ PEXELS_API_KEY = os.getenv("PEXELS_API_KEY")
|
|
25 |
MODEL_NAME = "DeepESP/gpt2-spanish" # Modelo en espa帽ol m谩s ligero
|
26 |
|
27 |
# Lista de voces disponibles
|
28 |
-
VOICES = asyncio.run(edge_tts.list_voices())
|
29 |
VOICE_NAMES = [f"{v['Name']} ({v['Gender']}, {v['LocaleName']})" for v in VOICES]
|
30 |
|
31 |
def generar_guion_profesional(prompt):
|
@@ -149,7 +149,7 @@ def buscar_videos_avanzado(prompt, guion, num_videos=5):
|
|
149 |
)
|
150 |
return response.json().get('videos', [])[:num_videos]
|
151 |
|
152 |
-
def crear_video_profesional(prompt, custom_script, voz_index, musica=None):
|
153 |
try:
|
154 |
# 1. Generar o usar guion
|
155 |
guion = custom_script if custom_script else generar_guion_profesional(prompt)
|
@@ -160,7 +160,7 @@ def crear_video_profesional(prompt, custom_script, voz_index, musica=None):
|
|
160 |
|
161 |
# 3. Generar voz
|
162 |
voz_archivo = "voz.mp3"
|
163 |
-
|
164 |
audio = AudioFileClip(voz_archivo)
|
165 |
duracion_total = audio.duration
|
166 |
|
@@ -241,6 +241,9 @@ def crear_video_profesional(prompt, custom_script, voz_index, musica=None):
|
|
241 |
if os.path.exists(voz_archivo):
|
242 |
os.remove(voz_archivo)
|
243 |
|
|
|
|
|
|
|
244 |
# Interfaz profesional
|
245 |
with gr.Blocks(theme=gr.themes.Soft(), title="Generador de Videos Profesional") as app:
|
246 |
gr.Markdown("# 馃幀 GENERADOR DE VIDEOS CON IA")
|
@@ -284,7 +287,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Generador de Videos Profesional")
|
|
284 |
)
|
285 |
|
286 |
btn.click(
|
287 |
-
fn=
|
288 |
inputs=[prompt, custom_script, voz, musica],
|
289 |
outputs=output
|
290 |
)
|
|
|
10 |
import numpy as np
|
11 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
12 |
import nltk
|
|
|
13 |
import random
|
14 |
from transformers import pipeline
|
15 |
import torch
|
16 |
+
import asyncio # 隆Importaci贸n cr铆tica que faltaba!
|
17 |
|
18 |
# Configuraci贸n inicial
|
19 |
+
nltk.download('punkt', quiet=True)
|
20 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
21 |
logger = logging.getLogger(__name__)
|
22 |
|
|
|
25 |
MODEL_NAME = "DeepESP/gpt2-spanish" # Modelo en espa帽ol m谩s ligero
|
26 |
|
27 |
# Lista de voces disponibles
|
28 |
+
VOICES = asyncio.run(edge_tts.list_voices()) # Ahora funciona correctamente
|
29 |
VOICE_NAMES = [f"{v['Name']} ({v['Gender']}, {v['LocaleName']})" for v in VOICES]
|
30 |
|
31 |
def generar_guion_profesional(prompt):
|
|
|
149 |
)
|
150 |
return response.json().get('videos', [])[:num_videos]
|
151 |
|
152 |
+
async def crear_video_profesional(prompt, custom_script, voz_index, musica=None):
|
153 |
try:
|
154 |
# 1. Generar o usar guion
|
155 |
guion = custom_script if custom_script else generar_guion_profesional(prompt)
|
|
|
160 |
|
161 |
# 3. Generar voz
|
162 |
voz_archivo = "voz.mp3"
|
163 |
+
await edge_tts.Communicate(guion, voz_seleccionada).save(voz_archivo)
|
164 |
audio = AudioFileClip(voz_archivo)
|
165 |
duracion_total = audio.duration
|
166 |
|
|
|
241 |
if os.path.exists(voz_archivo):
|
242 |
os.remove(voz_archivo)
|
243 |
|
244 |
+
def run_async_func(prompt, custom_script, voz_index, musica=None):
|
245 |
+
return asyncio.run(crear_video_profesional(prompt, custom_script, voz_index, musica))
|
246 |
+
|
247 |
# Interfaz profesional
|
248 |
with gr.Blocks(theme=gr.themes.Soft(), title="Generador de Videos Profesional") as app:
|
249 |
gr.Markdown("# 馃幀 GENERADOR DE VIDEOS CON IA")
|
|
|
287 |
)
|
288 |
|
289 |
btn.click(
|
290 |
+
fn=run_async_func,
|
291 |
inputs=[prompt, custom_script, voz, musica],
|
292 |
outputs=output
|
293 |
)
|