Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,7 @@ from dotenv import load_dotenv
|
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
-
def
|
| 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 |
|
|
@@ -17,7 +14,7 @@ async def synthesize(article_url, text_input, language):
|
|
| 17 |
config = ConversationConfig()
|
| 18 |
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
| 19 |
|
| 20 |
-
# Voces
|
| 21 |
voices = {
|
| 22 |
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
| 23 |
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
|
@@ -25,34 +22,28 @@ async def synthesize(article_url, text_input, language):
|
|
| 25 |
voice1, voice2 = voices.get(language, voices["en"])
|
| 26 |
|
| 27 |
if text_input:
|
| 28 |
-
|
| 29 |
-
conversation_json = converter.extract_conversation(text_input)
|
| 30 |
-
conversation_text = "\n".join(
|
| 31 |
-
f"{turn['speaker']}: {turn['text']}"
|
| 32 |
-
for turn in conversation_json["conversation"]
|
| 33 |
-
)
|
| 34 |
-
audio_files, _ = await converter.text_to_speech(conversation_json, voice1, voice2)
|
| 35 |
-
output_file = os.path.join("combined_output.wav")
|
| 36 |
-
converter.combine_audio_files(audio_files, output_file)
|
| 37 |
else:
|
| 38 |
-
|
| 39 |
-
output_file, conversation_text = await converter.url_to_audio(article_url, voice1, voice2)
|
| 40 |
|
| 41 |
-
return
|
| 42 |
except Exception as e:
|
| 43 |
return f"Error: {str(e)}", None
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Blocks(theme='gstaff/sketch') as demo:
|
| 46 |
gr.Markdown("# 🎙 Podcast Converter (Human Voices)")
|
| 47 |
with gr.Group():
|
| 48 |
-
text_url = gr.Textbox(label="
|
| 49 |
-
text_input = gr.Textbox(label="
|
| 50 |
-
language = gr.Dropdown(["en", "es"], label="
|
| 51 |
-
btn = gr.Button("
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
-
conv_display = gr.Textbox(label="
|
| 55 |
-
aud = gr.Audio(label="
|
| 56 |
|
| 57 |
btn.click(
|
| 58 |
synthesize_sync,
|
|
|
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
+
async def synthesize(article_url, text_input, language="en"):
|
|
|
|
|
|
|
|
|
|
| 10 |
if not article_url and not text_input:
|
| 11 |
return "Error: Ingresa una URL o texto", None
|
| 12 |
|
|
|
|
| 14 |
config = ConversationConfig()
|
| 15 |
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
| 16 |
|
| 17 |
+
# Voces humanizadas
|
| 18 |
voices = {
|
| 19 |
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
| 20 |
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
|
|
|
| 22 |
voice1, voice2 = voices.get(language, voices["en"])
|
| 23 |
|
| 24 |
if text_input:
|
| 25 |
+
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
else:
|
| 27 |
+
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
|
|
|
|
| 28 |
|
| 29 |
+
return conversation, output_file
|
| 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,
|