Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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()
|