Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import asyncio
|
4 |
-
import
|
5 |
-
from
|
6 |
-
from pydub import AudioSegment
|
7 |
-
import io
|
8 |
|
9 |
-
|
10 |
-
pipe = pipeline(
|
11 |
-
"text-generation",
|
12 |
-
model="OpenAssistant/llama2-7b-orca-8k-3319",
|
13 |
-
device="cpu",
|
14 |
-
torch_dtype=torch.float32
|
15 |
-
)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
# Mock: Guarda un audio vacío (implementa TTS real aquí)
|
20 |
-
audio_path = "output.mp3"
|
21 |
-
AudioSegment.silent(duration=1000).export(audio_path, format="mp3")
|
22 |
-
return audio_path
|
23 |
|
24 |
-
async def synthesize(
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
return "Error: No hay texto para procesar", None
|
30 |
-
|
31 |
-
# Genera diálogo en el idioma del texto
|
32 |
-
prompt = f"Convierte esto en un diálogo de podcast (en {language}): {text}"
|
33 |
-
output = pipe(prompt, max_length=1000)
|
34 |
-
conversation = output[0]["generated_text"]
|
35 |
-
|
36 |
-
# Convierte a audio (simulado)
|
37 |
-
audio_path = text_to_speech(conversation, language)
|
38 |
-
return conversation, audio_path
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
# Interfaz
|
44 |
with gr.Blocks(theme='gstaff/sketch') as demo:
|
45 |
-
gr.Markdown("#
|
46 |
-
gr.Markdown("### Soporta español/otros idiomas (sin GPU/API)")
|
47 |
-
|
48 |
with gr.Group():
|
49 |
text_url = gr.Textbox(label="URL del artículo (opcional)", placeholder="Ej: https://example.com")
|
50 |
-
text_input = gr.Textbox(label="O pega el texto aquí", lines=5, placeholder="
|
51 |
-
|
52 |
-
label="Idioma",
|
53 |
-
choices=["es", "en", "fr", "de"],
|
54 |
-
value="es"
|
55 |
-
)
|
56 |
-
btn = gr.Button("Generar Podcast", variant="primary")
|
57 |
|
58 |
with gr.Row():
|
59 |
-
conv_display = gr.Textbox(label="Conversación
|
60 |
-
aud = gr.Audio(label="Podcast", interactive=False)
|
61 |
|
62 |
btn.click(
|
63 |
synthesize_sync,
|
64 |
-
inputs=[text_url, text_input
|
65 |
outputs=[conv_display, aud]
|
66 |
)
|
67 |
|
68 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import asyncio
|
4 |
+
from conver import ConversationConfig, URLToAudioConverter
|
5 |
+
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()
|