File size: 1,688 Bytes
039f896
 
 
280807d
 
039f896
280807d
039f896
280807d
 
039f896
280807d
 
 
 
 
039f896
280807d
 
 
 
 
 
 
 
 
 
 
 
039f896
 
280807d
039f896
 
280807d
 
039f896
 
280807d
 
039f896
 
 
280807d
039f896
 
 
280807d
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
import gradio as gr
import os
import asyncio
from conver import ConversationConfig, URLToAudioConverter
from dotenv import load_dotenv

load_dotenv()

def synthesize_sync(article_url, text_input):
    return asyncio.run(synthesize(article_url, text_input))

async def synthesize(article_url, text_input):
    # Si hay texto manual, úsalo; si no, usa la URL
    input_text = text_input if text_input else article_url
    if not input_text:
        return "Ingresa una URL o texto", None

    try:
        config = ConversationConfig()
        converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
        
        output_file, conversation = await converter.url_to_audio(
            input_text, 
            "es-ES-AlvaroNeural",  # Voz en español
            "es-ES-ElviraNeural"   # Segunda voz en español
        )
        return conversation, output_file
    except Exception as e:
        return f"Error: {str(e)}", None

with gr.Blocks(theme='gstaff/sketch') as demo:
    gr.Markdown("# Convertir Artículo/Texto en Podcast")
    with gr.Group():
        text_url = gr.Textbox(label="URL del artículo (opcional)", placeholder="Ej: https://example.com")
        text_input = gr.Textbox(label="O pega el texto aquí", lines=5, placeholder="Texto en español...")
        btn = gr.Button("Podcastify", variant="primary")
    
    with gr.Row():
        conv_display = gr.Textbox(label="Conversación", interactive=False, lines=10)
        aud = gr.Audio(label="Podcast generado", interactive=False)
    
    btn.click(
        synthesize_sync,
        inputs=[text_url, text_input],
        outputs=[conv_display, aud]
    )

demo.queue().launch()