gnosticdev commited on
Commit
59b69bc
·
verified ·
1 Parent(s): 885ea0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -20
app.py CHANGED
@@ -30,25 +30,40 @@ async def synthesize(article_url, text_input, language="en"):
30
  except Exception as e:
31
  return f"Error: {str(e)}", None
32
 
33
- def synthesize_sync(article_url, text_input, language):
34
- return asyncio.run(synthesize(article_url, text_input, language))
35
-
36
- with gr.Blocks(theme='gstaff/sketch') as demo:
37
- gr.Markdown("# 🎙 Podcast Converter (Human Voices)")
38
- with gr.Group():
39
- text_url = gr.Textbox(label="URL (opcional)", placeholder="https://...")
40
- text_input = gr.Textbox(label="O texto directo", lines=5)
41
- language = gr.Dropdown(["en", "es"], label="Idioma", value="en")
42
- btn = gr.Button("Generar Podcast", variant="primary")
43
-
44
- with gr.Row():
45
- conv_display = gr.Textbox(label="Conversación", interactive=False, lines=10)
46
- aud = gr.Audio(label="Audio Generado", interactive=False)
47
-
48
- btn.click(
49
- synthesize_sync,
50
- inputs=[text_url, text_input, language],
51
- outputs=[conv_display, aud]
52
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  demo.launch()
 
30
  except Exception as e:
31
  return f"Error: {str(e)}", None
32
 
33
+ async def synthesize(article_url, text_input, language="en", skip_llm=False):
34
+ if not article_url and not text_input:
35
+ return "Error: Ingresa una URL o texto", None
36
+
37
+ try:
38
+ config = ConversationConfig()
39
+ converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
40
+
41
+ voices = {
42
+ "en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
43
+ "es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
44
+ }
45
+ voice1, voice2 = voices.get(language, voices["en"])
46
+
47
+ # Modo sin LLM (texto exacto)
48
+ if skip_llm and text_input:
49
+ return await converter.raw_text_to_audio(text_input, voice1, voice2)
50
+
51
+ # Procesamiento normal (con LLM)
52
+ if text_input:
53
+ output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
54
+ else:
55
+ output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
56
+
57
+ return conversation, output_file
58
+ except Exception as e:
59
+ return f"Error: {str(e)}", None
60
+
61
+ # Añade esto en tu interfaz (dentro de with gr.Blocks()):
62
+ skip_llm = gr.Checkbox(label="🔴 Modo libre (sin filtros LLM)", value=False)
63
+ btn.click(
64
+ synthesize_sync,
65
+ inputs=[text_url, text_input, language, skip_llm],
66
+ outputs=[conv_display, aud]
67
+ )
68
 
69
  demo.launch()