gnosticdev commited on
Commit
996224c
·
verified ·
1 Parent(s): 280807d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -21
app.py CHANGED
@@ -6,43 +6,65 @@ from dotenv import load_dotenv
6
 
7
  load_dotenv()
8
 
9
- def synthesize_sync(article_url, text_input):
10
- return asyncio.run(synthesize(article_url, text_input))
11
 
12
- async def synthesize(article_url, text_input):
13
- # Si hay texto manual, úsalo; si no, usa la URL
14
- input_text = text_input if text_input else article_url
15
- if not input_text:
16
- return "Ingresa una URL o texto", None
17
 
18
  try:
19
  config = ConversationConfig()
20
  converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
21
 
22
- output_file, conversation = await converter.url_to_audio(
23
- input_text,
24
- "es-ES-AlvaroNeural", # Voz en español
25
- "es-ES-ElviraNeural" # Segunda voz en español
26
- )
27
- return conversation, output_file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  except Exception as e:
29
  return f"Error: {str(e)}", None
30
 
31
  with gr.Blocks(theme='gstaff/sketch') as demo:
32
- gr.Markdown("# Convertir Artículo/Texto en Podcast")
33
  with gr.Group():
34
- text_url = gr.Textbox(label="URL del artículo (opcional)", placeholder="Ej: https://example.com")
35
- text_input = gr.Textbox(label="O pega el texto aquí", lines=5, placeholder="Texto en español...")
36
- btn = gr.Button("Podcastify", variant="primary")
 
 
 
 
 
37
 
38
  with gr.Row():
39
- conv_display = gr.Textbox(label="Conversación", interactive=False, lines=10)
40
- aud = gr.Audio(label="Podcast generado", interactive=False)
41
 
42
  btn.click(
43
  synthesize_sync,
44
- inputs=[text_url, text_input],
45
  outputs=[conv_display, aud]
46
  )
47
 
48
- demo.queue().launch()
 
6
 
7
  load_dotenv()
8
 
9
+ def synthesize_sync(article_url, text_input, language="en"):
10
+ return asyncio.run(synthesize(article_url, text_input, language))
11
 
12
+ async def synthesize(article_url, text_input, language):
13
+ if not article_url and not text_input:
14
+ return "Error: Ingresa una URL o texto", None
 
 
15
 
16
  try:
17
  config = ConversationConfig()
18
  converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
19
 
20
+ # Definir voces según idioma (puedes añadir más)
21
+ voices = {
22
+ "en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"), # Voces originales humanizadas
23
+ "es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural") # Voces en español
24
+ }
25
+ voice1, voice2 = voices.get(language, voices["en"]) # Default: inglés
26
+
27
+ # Procesar texto manual
28
+ if text_input:
29
+ output_file, conversation = await converter.text_to_audio(
30
+ text_input,
31
+ voice1,
32
+ voice2
33
+ )
34
+ return conversation, output_file
35
+
36
+ # Procesar URL
37
+ else:
38
+ output_file, conversation = await converter.url_to_audio(
39
+ article_url,
40
+ voice1,
41
+ voice2
42
+ )
43
+ return conversation, output_file
44
+
45
  except Exception as e:
46
  return f"Error: {str(e)}", None
47
 
48
  with gr.Blocks(theme='gstaff/sketch') as demo:
49
+ gr.Markdown("# 🎙 Podcast Converter (Human-like Voices)")
50
  with gr.Group():
51
+ text_url = gr.Textbox(label="Article URL (optional)", placeholder="https://...")
52
+ text_input = gr.Textbox(label="Or paste text directly", lines=5, placeholder="Type your content here...")
53
+ language = gr.Dropdown(
54
+ label="Language",
55
+ choices=["en", "es"], # Añade más si necesitas
56
+ value="en"
57
+ )
58
+ btn = gr.Button("Generate Podcast", variant="primary")
59
 
60
  with gr.Row():
61
+ conv_display = gr.Textbox(label="Conversation", interactive=False, lines=10)
62
+ aud = gr.Audio(label="Generated Podcast", interactive=False)
63
 
64
  btn.click(
65
  synthesize_sync,
66
+ inputs=[text_url, text_input, language],
67
  outputs=[conv_display, aud]
68
  )
69
 
70
+ demo.launch()