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