Spaces:
Running
Running
File size: 2,487 Bytes
fd43dfa 039f896 fd43dfa 039f896 fd43dfa 039f896 fd43dfa 039f896 fd43dfa 280807d fd43dfa 996224c fd43dfa 59b69bc fd43dfa |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
import os
import asyncio
from conver import ConversationConfig, URLToAudioConverter
from dotenv import load_dotenv
load_dotenv()
async def synthesize(article_url, text_input, language="en"):
if not article_url and not text_input:
return "Error: Ingresa una URL o texto", None
try:
config = ConversationConfig()
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
# Voces humanizadas
voices = {
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
}
voice1, voice2 = voices.get(language, voices["en"])
if text_input:
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
else:
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
return conversation, output_file
except Exception as e:
return f"Error: {str(e)}", None
async def synthesize(article_url, text_input, language="en", skip_llm=False):
if not article_url and not text_input:
return "Error: Ingresa una URL o texto", None
try:
config = ConversationConfig()
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
voices = {
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
}
voice1, voice2 = voices.get(language, voices["en"])
# Modo sin LLM (texto exacto)
if skip_llm and text_input:
return await converter.raw_text_to_audio(text_input, voice1, voice2)
# Procesamiento normal (con LLM)
if text_input:
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
else:
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
return conversation, output_file
except Exception as e:
return f"Error: {str(e)}", None
# Añade esto en tu interfaz (dentro de with gr.Blocks()):
skip_llm = gr.Checkbox(label="🔴 Modo libre (sin filtros LLM)", value=False)
btn.click(
synthesize_sync,
inputs=[text_url, text_input, language, skip_llm],
outputs=[conv_display, aud]
)
demo.launch() |